powerpc: updates, P10, PNV support
v4 cover powerpc: updates, P10, PNV support
Posting again, a couple of patches were merged and accounted for review comments from last time.
Thanks,
Nick
Nicholas Piggin (12):
powerpc: Report instruction address and MSR in unhandled exception
error
powerpc: Add some checking to exception handler install
powerpc: Abstract H_CEDE calls into a sleep functions
powerpc: Add ISA v3.1 (POWER10) support to SPR test
powerpc: Extract some common helpers and defines to headers powerpc/sprs: Specify SPRs with data rather than code powerpc/spapr_vpa: Add basic VPA tests
powerpc: Expand exception handler vector granularity
powerpc: Add support for more interrupts including HV interrupts
powerpc: Discover runtime load address dynamically
powerpc: Support powernv machine with QEMU TCG powerpc/sprs: Test hypervisor registers on powernv machine
lib/powerpc/asm/handlers.h | 2 +- lib/powerpc/asm/hcall.h | 1 + lib/powerpc/asm/ppc_asm.h | 9 + lib/powerpc/asm/processor.h | 55 ++- lib/powerpc/handlers.c | 10 +- lib/powerpc/hcall.c | 4 +- lib/powerpc/io.c | 27 +- lib/powerpc/io.h | 6 + lib/powerpc/processor.c | 79 ++++- lib/powerpc/setup.c | 8 +- lib/ppc64/asm/opal.h | 15 + lib/ppc64/asm/vpa.h | 62 ++++ lib/ppc64/opal-calls.S | 46 +++ lib/ppc64/opal.c | 74 +++++ powerpc/Makefile.ppc64 | 4 +- powerpc/cstart64.S | 105 ++++-- powerpc/run | 35 +- powerpc/spapr_hcall.c | 9 +- powerpc/spapr_vpa.c | 172 ++++++++++ powerpc/sprs.c | 645 ++++++++++++++++++++++++++---------- powerpc/tm.c | 20 +- powerpc/unittests.cfg | 3 + 22 files changed, 1133 insertions(+), 258 deletions(-) create mode 100644 lib/ppc64/asm/opal.h create mode 100644 lib/ppc64/asm/vpa.h create mode 100644 lib/ppc64/opal-calls.S create mode 100644 lib/ppc64/opal.c create mode 100644 powerpc/spapr_vpa.c
Signature · 1 line
2.40.1
PATCH v4 1/12 powerpc: Report instruction address and MSR in unhandled exception error
---
Since v3:
- New patch
lib/powerpc/processor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/powerpc/processor.c +1 -1
@@ -38,7 +38,7 @@ void do_handle_exception(struct pt_regs *regs)return ; } -printf ("unhandled cpu exception %#lx\n" , regs->trap); +printf ("unhandled cpu exception %#lx at NIA:0x%016lx MSR:0x%016lx\n" , regs->trap, regs->nip, regs->msr);abort (); }
Signature · 1 line
2.40.1
PATCH v4 2/12 powerpc: Add some checking to exception handler install
In reply to Nicholas PigginCheck to ensure exception handlers are not being overwritten or invalid exception numbers are used.
---
Since v3:
- Simplified code as suggested by Thomas.
lib/powerpc/processor.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
lib/powerpc/processor.c +7 -3
@@ -19,12 +19,16 @@ static struct {void handle_exception (int trap,void (*func)(struct pt_regs *,void *),void * data) { +assert (!(trap & ~0xf00 )); + trap >>=8 ; -if (trap <16 ) { - handlers[trap].func = func; - handlers[trap].data = data; +if (func && handlers[trap].func) { +printf ("exception handler installed twice %#x\n" , trap); +abort (); } + handlers[trap].func = func; + handlers[trap].data = data; }void do_handle_exception (struct pt_regs *regs)
Signature · 1 line
2.40.1
PATCH v4 3/12 powerpc: Abstract H_CEDE calls into a sleep functions
In reply to Nicholas PigginThis consolidates several implementations, and it no longer leaves MSR[EE] enabled after the decrementer interrupt is handled, but rather disables it on return.
The handler no longer allows a continuous ticking, but rather dec has to be re-armed and EE re-enabled (e.g., via H_CEDE hcall) each time.
--- lib/powerpc/asm/handlers.h | 2 +- lib/powerpc/asm/ppc_asm.h | 1 + lib/powerpc/asm/processor.h | 7 ++++++ lib/powerpc/handlers.c | 10 ++++----- lib/powerpc/processor.c | 43 +++++++++++++++++++++++++++++++++++++ powerpc/sprs.c | 6 +----- powerpc/tm.c | 20 +---------------- 7 files changed, 58 insertions(+), 31 deletions(-)
lib/powerpc/asm/handlers.h +1 -1
@@ -3,6 +3,6 @@#include <asm/ptrace.h> -void dec_except_handler (struct pt_regs *regs,void *data); +void dec_handler_oneshot (struct pt_regs *regs,void *data);#endif /* _ASMPOWERPC_HANDLERS_H_ */
lib/powerpc/asm/ppc_asm.h +1 -0
@@ -36,6 +36,7 @@#endif /* __BYTE_ORDER__ */ /* Machine State Register definitions: */ +#define MSR_EE_BIT 15/* External Interrupts Enable */ #define MSR_SF_BIT 63/* 64-bit mode */ #endif /* _ASMPOWERPC_PPC_ASM_H */
lib/powerpc/asm/processor.h +7 -0
@@ -20,6 +20,8 @@ static inline uint64_t get_tb(void)extern void delay (uint64_t cycles);extern void udelay (uint64_t us); +extern void sleep_tb (uint64_t cycles); +extern void usleep (uint64_t us);static inline void mdelay (uint64_t ms) {
@@ -27,4 +29,9 @@ static inline void mdelay(uint64_t ms) udelay(1000); } +static inline void msleep (uint64_t ms) +{ +usleep (ms *1000 ); +} +#endif /* _ASMPOWERPC_PROCESSOR_H_ */
lib/powerpc/handlers.c +4 -6
@@ -9,15 +9,13 @@#include <libcflat.h> #include <asm/handlers.h> #include <asm/ptrace.h> +#include <asm/ppc_asm.h> /* * Generic handler for decrementer exceptions (0x900) -* Just reset the decrementer back to the value specified when registering the -* handler +* Return with MSR[EE] disabled. */ -void dec_except_handler(struct pt_regs *regs __unused, void *data) +void dec_handler_oneshot (struct pt_regs *regs,void *data) { -uint64_t dec = *((uint64_t *) data); - - asmvolatile ("mtdec %0" : :"r" (dec)); + regs->msr &= ~(1UL <<MSR_EE_BIT ); }
lib/powerpc/processor.c +43 -0
52 lines not on this page · raw message
powerpc/sprs.c +1 -5
@@ -254,7 +254,6 @@ int main(int argc, char **argv)0x1234567890ABCDEFULL ,0xFEDCBA0987654321ULL , -1ULL, }; -static uint64_t decr =0x7FFFFFFF ;/* Max value */ for (i =1 ; i < argc; i++) {if (!strcmp (argv[i],"-w" )) {
@@ -288,10 +287,7 @@ int main(int argc, char **argv)if (pause) {migrate_once (); }else { -puts ("Sleeping...\n" ); -handle_exception (0x900 , &dec_except_handler, &decr); - asmvolatile ("mtdec %0" : :"r" (0x3FFFFFFF )); -hcall (H_CEDE ); +msleep (2000 ); }get_sprs (after);
powerpc/tm.c +1 -19
@@ -48,17 +48,6 @@ static int count_cpus_with_tm(void)return available; } -static int h_cede (void ) -{ - register uint64_t r3 asm("r3") = H_CEDE; - - asmvolatile ("sc 1" :"+r" (r3) : - :"r0" ,"r4" ,"r5" ,"r6" ,"r7" ,"r8" ,"r9" , -"r10" ,"r11" ,"r12" ,"xer" ,"ctr" ,"cc" ); - -return r3; -} -/* * Enable transactional memory * Returns: FALSE - Failure
@@ -95,14 +84,10 @@ static bool enable_tm(void)static void test_h_cede_tm (int argc,char **argv) {int i; -static uint64_t decr =0x3FFFFF ;/* ~10ms */ if (argc >2 )report_abort ("Unsupported argument: '%s'" , argv[2 ]); -handle_exception (0x900 , &dec_except_handler, &decr); - asmvolatile ("mtdec %0" : :"r" (decr)); -if (!start_all_cpus (halt,0 ))report_abort ("Failed to start secondary cpus" );
@@ -120,10 +105,7 @@ static void test_h_cede_tm(int argc, char **argv) "bf 2,1b" : : : "cr0"); for (i = 0; i < 500; i++) { -uint64_t rval =h_cede (); - -if (rval !=H_SUCCESS ) -break ; +msleep (10 );mdelay (5 ); }
Signature · 1 line
2.40.1
PATCH v4 4/12 powerpc: Add ISA v3.1 (POWER10) support to SPR test
In reply to Nicholas PigginThis is a very basic detection that does not include all new SPRs.
--- powerpc/sprs.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
powerpc/sprs.c +22 -0
@@ -117,6 +117,15 @@ static void set_sprs_book3s_300(uint64_t val)mtspr (823 , val);/* PSSCR */ } +/* SPRs from Power ISA Version 3.1B */ +static void set_sprs_book3s_31 (uint64_t val) +{ +set_sprs_book3s_207 (val); +mtspr (48 , val);/* PIDR */ +/* 3.1 removes TIDR */ +mtspr (823 , val);/* PSSCR */ +} +static void set_sprs (uint64_t val) {uint32_t pvr =mfspr (287 );/* Processor Version Register */
@@ -137,6 +146,9 @@ static void set_sprs(uint64_t val)case 0x4e :/* POWER9 */ set_sprs_book3s_300 (val);break ; +case 0x80 :/* POWER10 */ +set_sprs_book3s_31 (val); +break ;default :puts ("Warning: Unknown processor version!\n" ); }
@@ -220,6 +232,13 @@ static void get_sprs_book3s_300(uint64_t *v) v[823 ] =mfspr (823 );/* PSSCR */ } +static void get_sprs_book3s_31 (uint64_t *v) +{ +get_sprs_book3s_207 (v); + v[48 ] =mfspr (48 );/* PIDR */ + v[823 ] =mfspr (823 );/* PSSCR */ +} +static void get_sprs (uint64_t *v) {uint32_t pvr =mfspr (287 );/* Processor Version Register */
@@ -240,6 +259,9 @@ static void get_sprs(uint64_t *v)case 0x4e :/* POWER9 */ get_sprs_book3s_300 (v);break ; +case 0x80 :/* POWER10 */ +get_sprs_book3s_31 (v); +break ; } }
Signature · 1 line
2.40.1
PATCH v4 5/12 powerpc: Extract some common helpers and defines to headers
In reply to Nicholas PigginMove some common helpers and defines to processor.h.
--- lib/powerpc/asm/processor.h | 38 +++++++++++++++++++++++++++++++++---- powerpc/spapr_hcall.c | 9 +-------- powerpc/sprs.c | 9 --------- 3 files changed, 35 insertions(+), 21 deletions(-)
lib/powerpc/asm/processor.h +34 -4
@@ -9,13 +9,43 @@ void handle_exception(int trap, void (*func)(struct pt_regs *, void *), void *);void do_handle_exception (struct pt_regs *regs);#endif /* __ASSEMBLY__ */ -static inline uint64_t get_tb (void ) +#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 tb; +uint64_t ret; + + asmvolatile ("mfspr %0,%1" :"=r" (ret) :"i" (nr) :"memory" ); + +return ret; +} - asmvolatile ("mfspr %[tb],268" : [tb]"=r" (tb)); +static inline void mtspr (int nr,uint64_t val) +{ + asmvolatile ("mtspr %0,%1" : :"i" (nr),"r" (val) :"memory" ); +} + +static inline uint64_t mfmsr (void ) +{ +uint64_t msr; -return tb; + asmvolatile ("mfmsr %[msr]" : [msr]"=r" (msr) ::"memory" ); + +return msr; +} + +static inline void mtmsr (uint64_t msr) +{ + asmvolatile ("mtmsrd %[msr]" :: [msr]"r" (msr) :"memory" ); +} + +static inline uint64_t get_tb (void ) +{ +return mfspr (SPR_TB ); }extern void delay (uint64_t cycles);
powerpc/spapr_hcall.c +1 -8
@@ -9,20 +9,13 @@#include <util.h> #include <alloc.h> #include <asm/hcall.h> +#include <asm/processor.h> #define PAGE_SIZE 4096#define H_ZERO_PAGE (1UL << (63-48))#define H_COPY_PAGE (1UL << (63-49)) -#define mfspr (nr) ({ \ - uint64_t ret; \ - asm volatile("mfspr %0,%1" : "=r"(ret) : "i"(nr)); \ - ret; \ -}) - -#define SPR_SPRG0 0x110 -/** * Test the H_SET_SPRG0 h-call by setting some values and checking whether * the SPRG0 register contains the correct values afterwards
powerpc/sprs.c +0 -9
@@ -28,15 +28,6 @@#include <asm/processor.h> #include <asm/barrier.h> -#define mfspr (nr) ({ \ - uint64_t ret; \ - asm volatile("mfspr %0,%1" : "=r"(ret) : "i"(nr)); \ - ret; \ -}) - -#define mtspr (nr, val) \ - asm volatile("mtspr %0,%1" : : "i"(nr), "r"(val)) -uint64_t before[1024 ], after[1024 ];/* Common SPRs for all PowerPC CPUs */
Signature · 1 line
2.40.1
PATCH v4 6/12 powerpc/sprs: Specify SPRs with data rather than code
In reply to Nicholas PigginA 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.
---
This ended up a little over-engineered perhaps, but there are lots of SPRs, lots of access types, lots of changes between processor and ISA versions, and lots of places they are implemented and used, so lots of room for mistakes. There is not a good system in place to easily see that userspace, supervisor, etc., switches perform all the right SPR context switching so this is a nice test case to have. The sprs test quickly caught a few QEMU TCG SPR bugs which really motivated me to improve the SPR coverage.
--- powerpc/sprs.c | 643 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 450 insertions(+), 193 deletions(-)
powerpc/sprs.c +450 -193
@@ -28,231 +28,465 @@#include <asm/processor.h> #include <asm/barrier.h> -uint64_t before[1024 ], after[1024 ]; - -/* Common SPRs for all PowerPC CPUs */ -static void set_sprs_common (uint64_t val) +/* "Indirect" mfspr/mtspr which accept a non-constant spr number */ +static uint64_t __mfspr (unsigned spr) { -mtspr (9 , val);/* CTR */ -// mtspr(273, val); /* SPRG1 */ /* Used by our exception handler */ -mtspr (274 , val);/* SPRG2 */ -mtspr (275 , val);/* SPRG3 */ +uint64_t tmp; +uint64_t ret; + + asmvolatile ( +" bcl 20, 31, 1f \n" +"1: mflr %0 \n" +" addi %0, %0, (2f-1b) \n" +" add %0, %0, %2 \n" +" mtctr %0 \n" +" bctr \n" +"2: \n" +".LSPR=0 \n" +".rept 1024 \n" +" mfspr %1, .LSPR \n" +" b 3f \n" +" .LSPR=.LSPR+1 \n" +".endr \n" +"3: \n" + :"=&r" (tmp), +"=r" (ret) + :"r" (spr*8 )/* 8 bytes per 'mfspr ; b' block */ + :"lr" ,"ctr" ); + +return ret; } -/* SPRs from PowerPC Operating Environment Architecture, Book III, Vers. 2.01 */ -static void set_sprs_book3s_201 (uint64_t val) +static void __mtspr (unsigned spr,uint64_t val) { -mtspr (18 , val);/* DSISR */ -mtspr (19 , val);/* DAR */ -mtspr (152 , val);/* CTRL */ -mtspr (256 , val);/* VRSAVE */ -mtspr (786 , val);/* MMCRA */ -mtspr (795 , val);/* MMCR0 */ -mtspr (798 , val);/* MMCR1 */ +uint64_t tmp; + + asmvolatile ( +" bcl 20, 31, 1f \n" +"1: mflr %0 \n" +" addi %0, %0, (2f-1b) \n" +" add %0, %0, %2 \n" +" mtctr %0 \n" +" bctr \n" +"2: \n" +".LSPR=0 \n" +".rept 1024 \n" +" mtspr .LSPR, %1 \n" +" b 3f \n" +" .LSPR=.LSPR+1 \n" +".endr \n" +"3: \n" + :"=&r" (tmp) + :"r" (val), +"r" (spr*8 )/* 8 bytes per 'mfspr ; b' block */ + :"lr" ,"ctr" ,"xer" ); } +static uint64_t before[1024 ], after[1024 ]; + +#define SPR_PR_READ 0x0001 +#define SPR_PR_WRITE 0x0002 +#define SPR_OS_READ 0x0010 +#define SPR_OS_WRITE 0x0020 +#define SPR_HV_READ 0x0100 +#define SPR_HV_WRITE 0x0200 + +#define RW 0x333 +#define RO 0x111 +#define WO 0x222 +#define OS_RW 0x330 +#define OS_RO 0x110 +#define OS_WO 0x220 +#define HV_RW 0x300 +#define HV_RO 0x100 +#define HV_WO 0x200 + +#define SPR_ASYNC 0x1000/* May be updated asynchronously */ +#define SPR_INT 0x2000/* May be updated by synchronous interrupt */ +#define SPR_HARNESS 0x4000/* Test harness uses the register */ + +struct spr { +const char *name; +uint8_t width; +uint16_t access; +uint16_t type; +}; + +/* SPRs common denominator back to PowerPC Operating Environment Architecture */ +static const struct spr sprs_common[1024 ] = { + [1 ] = {"XER" ,64 ,RW ,SPR_HARNESS , },/* Compiler */ + [8 ] = {"LR" ,64 ,RW ,SPR_HARNESS , },/* Compiler, mfspr/mtspr */ + [9 ] = {"CTR" ,64 ,RW ,SPR_HARNESS , },/* Compiler, mfspr/mtspr */ + [18 ] = {"DSISR" ,32 ,OS_RW ,SPR_INT , }, + [19 ] = {"DAR" ,64 ,OS_RW ,SPR_INT , }, + [26 ] = {"SRR0" ,64 ,OS_RW ,SPR_INT , }, + [27 ] = {"SRR1" ,64 ,OS_RW ,SPR_INT , }, +[268 ] = {"TB" ,64 ,RO ,SPR_ASYNC , }, +[269 ] = {"TBU" ,32 ,RO ,SPR_ASYNC , }, +[272 ] = {"SPRG0" ,64 ,OS_RW ,SPR_HARNESS , },/* Int stack */ +[273 ] = {"SPRG1" ,64 ,OS_RW ,SPR_HARNESS , },/* Scratch */ +[274 ] = {"SPRG2" ,64 ,OS_RW , }, +[275 ] = {"SPRG3" ,64 ,OS_RW , }, +[287 ] = {"PVR" ,32 ,OS_RO , }, +}; + +/* SPRs from PowerPC Operating Environment Architecture, Book III, Vers. 2.01 */ +static const struct spr sprs_201[1024 ] = { + [22 ] = {"DEC" ,32 ,OS_RW ,SPR_ASYNC , }, + [25 ] = {"SDR1" ,64 ,HV_RW |OS_RO , }, + [29 ] = {"ACCR" ,64 ,OS_RW , }, +[136 ] = {"CTRL" ,32 ,RO , }, +[152 ] = {"CTRL" ,32 ,OS_WO , }, +[259 ] = {"SPRG3" ,64 ,RO , }, +/* ASR, EAR omitted */ +[268 ] = {"TB" ,64 ,RO , }, +[269 ] = {"TBU" ,32 ,RO , }, +[284 ] = {"TBL" ,32 ,HV_WO , }, +[285 ] = {"TBU" ,32 ,HV_WO , }, +[310 ] = {"HDEC" ,32 ,HV_RW , }, +[1013 ]= {"DABR" ,64 ,HV_RW |OS_RO , }, +[1023 ]= {"PIR" ,32 ,OS_RO , }, +}; + +static const struct spr sprs_970_pmu[1024 ] = { +/* POWER4+ PMU, should find PPC970 and confirm */ +[770 ] = {"MMCRA" ,64 ,RO , }, +[771 ] = {"PMC1" ,32 ,RO , }, +[772 ] = {"PMC2" ,32 ,RO , }, +[773 ] = {"PMC3" ,32 ,RO , }, +[774 ] = {"PMC4" ,32 ,RO , }, +[775 ] = {"PMC5" ,32 ,RO , }, +[776 ] = {"PMC6" ,32 ,RO , }, +[777 ] = {"PMC7" ,32 ,RO , }, +[778 ] = {"PMC8" ,32 ,RO , }, +[779 ] = {"MMCR0" ,64 ,RO , }, +[780 ] = {"SIAR" ,64 ,RO , }, +[781 ] = {"SDAR" ,64 ,RO , }, +[782 ] = {"MMCR1" ,64 ,RO , }, +[786 ] = {"MMCRA" ,64 ,OS_RW , }, +[787 ] = {"PMC1" ,32 ,OS_RW , }, +[788 ] = {"PMC2" ,32 ,OS_RW , }, +[789 ] = {"PMC3" ,32 ,OS_RW , }, +[790 ] = {"PMC4" ,32 ,OS_RW , }, +[791 ] = {"PMC5" ,32 ,OS_RW , }, +[792 ] = {"PMC6" ,32 ,OS_RW , }, +[793 ] = {"PMC7" ,32 ,OS_RW , }, +[794 ] = {"PMC8" ,32 ,OS_RW , }, +[795 ] = {"MMCR0" ,64 ,OS_RW , }, +[796 ] = {"SIAR" ,64 ,OS_RW , }, +[797 ] = {"SDAR" ,64 ,OS_RW , }, +[798 ] = {"MMCR1" ,64 ,OS_RW , }, +}; + +/* These are common SPRs from 2.07S onward (POWER CPUs that support KVM HV) */ +static const struct spr sprs_power_common[1024 ] = { + [3 ] = {"DSCR" ,64 ,RW , }, + [13 ] = {"AMR" ,64 ,RW , }, + [17 ] = {"DSCR" ,64 ,OS_RW , }, + [28 ] = {"CFAR" ,64 ,OS_RW ,SPR_ASYNC , },/* Effectively async */ + [29 ] = {"AMR" ,64 ,OS_RW , }, + [61 ] = {"IAMR" ,64 ,OS_RW , }, +[136 ] = {"CTRL" ,32 ,RO , }, +[152 ] = {"CTRL" ,32 ,OS_WO , }, +[153 ] = {"FSCR" ,64 ,OS_RW , }, +[157 ] = {"UAMOR" ,64 ,OS_RW , }, +[159 ] = {"PSPB" ,32 ,OS_RW , }, +[176 ] = {"DPDES" ,64 ,HV_RW |OS_RO , }, +[180 ] = {"DAWR0" ,64 ,HV_RW , }, +[186 ] = {"RPR" ,64 ,HV_RW , }, +[187 ] = {"CIABR" ,64 ,HV_RW , }, +[188 ] = {"DAWRX0" ,32 ,HV_RW , }, +[190 ] = {"HFSCR" ,64 ,HV_RW , }, +[256 ] = {"VRSAVE" ,32 ,RW , }, +[259 ] = {"SPRG3" ,64 ,RO , }, +[284 ] = {"TBL" ,32 ,HV_WO , }, +[285 ] = {"TBU" ,32 ,HV_WO , }, +[286 ] = {"TBU40" ,64 ,HV_WO , }, +[304 ] = {"HSPRG0" ,64 ,HV_RW , }, +[305 ] = {"HSPRG1" ,64 ,HV_RW , }, +[306 ] = {"HDSISR" ,32 ,HV_RW ,SPR_INT , }, +[307 ] = {"HDAR" ,64 ,HV_RW ,SPR_INT , }, +[308 ] = {"SPURR" ,64 ,HV_RW |OS_RO ,SPR_ASYNC , }, +[309 ] = {"PURR" ,64 ,HV_RW |OS_RO ,SPR_ASYNC , }, +[313 ] = {"HRMOR" ,64 ,HV_RW , }, +[314 ] = {"HSRR0" ,64 ,HV_RW ,SPR_INT , }, +[315 ] = {"HSRR1" ,64 ,HV_RW ,SPR_INT , }, +[318 ] = {"LPCR" ,64 ,HV_RW , }, +[319 ] = {"LPIDR" ,32 ,HV_RW , }, +[336 ] = {"HMER" ,64 ,HV_RW , }, +[337 ] = {"HMEER" ,64 ,HV_RW , }, +[338 ] = {"PCR" ,64 ,HV_RW , }, +[349 ] = {"AMOR" ,64 ,HV_RW , }, +[446 ] = {"TIR" ,64 ,OS_RO , }, +[800 ] = {"BESCRS" ,64 ,RW , }, +[801 ] = {"BESCRSU" ,32 ,RW , }, +[802 ] = {"BESCRR" ,64 ,RW , }, +[803 ] = {"BESCRRU" ,32 ,RW , }, +[804 ] = {"EBBHR" ,64 ,RW , }, +[805 ] = {"EBBRR" ,64 ,RW , }, +[806 ] = {"BESCR" ,64 ,RW , }, +[815 ] = {"TAR" ,64 ,RW , }, +[848 ] = {"IC" ,64 ,HV_RW |OS_RO ,SPR_ASYNC , }, +[849 ] = {"VTB" ,64 ,HV_RW |OS_RO ,SPR_ASYNC , }, +[896 ] = {"PPR" ,64 ,RW , }, +[898 ] = {"PPR32" ,32 ,RW , }, +[1023 ]= {"PIR" ,32 ,OS_RO , }, +}; + +static const struct spr sprs_tm[1024 ] = { +#if 0 + /* XXX: leave these out until enabling TM facility (and more testing) */ +[128] = {"TFHAR", 64, RW, }, +[129 ] = {"TFIAR" ,64 ,RW , }, +[130 ] = {"TEXASR" ,64 ,RW , }, +[131 ] = {"TEXASRU" ,32 ,RW , }, +#endif +}; +/* SPRs from PowerISA 2.07 Book III-S */ -static void set_sprs_book3s_207 (uint64_t val) -{ -mtspr (3 , val);/* DSCR */ -mtspr (13 , val);/* AMR */ -mtspr (17 , val);/* DSCR */ -mtspr (18 , val);/* DSISR */ -mtspr (19 , val);/* DAR */ -mtspr (29 , val);/* AMR */ -mtspr (61 , val);/* IAMR */ -// mtspr(152, val); /* CTRL */ /* TODO: Needs a fix in KVM */ -mtspr (153 , val);/* FSCR */ -mtspr (157 , val);/* UAMOR */ -mtspr (159 , val);/* PSPB */ -mtspr (256 , val);/* VRSAVE */ -// mtspr(272, val); /* SPRG0 */ /* Used by our exception handler */ -mtspr (769 , val);/* MMCR2 */ -mtspr (770 , val);/* MMCRA */ -mtspr (771 , val);/* PMC1 */ -mtspr (772 , val);/* PMC2 */ -mtspr (773 , val);/* PMC3 */ -mtspr (774 , val);/* PMC4 */ -mtspr (775 , val);/* PMC5 */ -mtspr (776 , val);/* PMC6 */ -mtspr (779 , (val &0xfffffffffbab3fffULL ) |0xfa0b2070 );/* MMCR0 */ -mtspr (784 , val);/* SIER */ -mtspr (785 , val);/* MMCR2 */ -mtspr (786 , val);/* MMCRA */ -mtspr (787 , val);/* PMC1 */ -mtspr (788 , val);/* PMC2 */ -mtspr (789 , val);/* PMC3 */ -mtspr (790 , val);/* PMC4 */ -mtspr (791 , val);/* PMC5 */ -mtspr (792 , val);/* PMC6 */ -mtspr (795 , (val &0xfffffffffbab3fffULL ) |0xfa0b2070 );/* MMCR0 */ -mtspr (796 , val);/* SIAR */ -mtspr (797 , val);/* SDAR */ -mtspr (798 , val);/* MMCR1 */ -mtspr (800 , val);/* BESCRS */ -mtspr (801 , val);/* BESCCRSU */ -mtspr (802 , val);/* BESCRR */ -mtspr (803 , val);/* BESCRRU */ -mtspr (804 , val);/* EBBHR */ -mtspr (805 , val);/* EBBRR */ -mtspr (806 , val);/* BESCR */ -mtspr (815 , val);/* TAR */ -} +static const struct spr sprs_207[1024 ] = { + [22 ] = {"DEC" ,32 ,OS_RW ,SPR_ASYNC , }, + [25 ] = {"SDR1" ,64 ,HV_RW , }, +[177 ] = {"DHDES" ,64 ,HV_RW , }, +[283 ] = {"CIR" ,32 ,OS_RO , }, +[310 ] = {"HDEC" ,32 ,HV_RW ,SPR_ASYNC , }, +[312 ] = {"RMOR" ,64 ,HV_RW , }, +[339 ] = {"HEIR" ,32 ,HV_RW , }, +};/* SPRs from PowerISA 3.00 Book III */ -static void set_sprs_book3s_300 (uint64_t val) -{ -set_sprs_book3s_207 (val); -mtspr (48 , val);/* PIDR */ -mtspr (144 , val);/* TIDR */ -mtspr (823 , val);/* PSSCR */ -} +static const struct spr sprs_300[1024 ] = { + [22 ] = {"DEC" ,64 ,OS_RW ,SPR_ASYNC , }, + [48 ] = {"PIDR" ,32 ,OS_RW , }, +[144 ] = {"TIDR" ,64 ,OS_RW , }, +[283 ] = {"CIR" ,32 ,OS_RO , }, +[310 ] = {"HDEC" ,64 ,HV_RW ,SPR_ASYNC , }, +[339 ] = {"HEIR" ,32 ,HV_RW , }, +[464 ] = {"PTCR" ,64 ,HV_RW , }, +[816 ] = {"ASDR" ,64 ,HV_RW ,SPR_INT }, +[823 ] = {"PSSCR" ,64 ,OS_RW , }, +[855 ] = {"PSSCR" ,64 ,HV_RW , }, +}; -/* SPRs from Power ISA Version 3.1B */ -static void set_sprs_book3s_31 (uint64_t val) -{ -set_sprs_book3s_207 (val); -mtspr (48 , val);/* PIDR */ -/* 3.1 removes TIDR */ -mtspr (823 , val);/* PSSCR */ -} +/* SPRs from PowerISA 3.1B Book III */ +static const struct spr sprs_31[1024 ] = { + [22 ] = {"DEC" ,64 ,OS_RW ,SPR_ASYNC , }, + [48 ] = {"PIDR" ,32 ,OS_RW , }, +[181 ] = {"DAWR1" ,64 ,HV_RW , }, +[189 ] = {"DAWRX1" ,32 ,HV_RW , }, +[310 ] = {"HDEC" ,64 ,HV_RW ,SPR_ASYNC , }, +[339 ] = {"HEIR" ,64 ,HV_RW , }, +[455 ] = {"HDEXCR" ,32 ,RO , }, +[464 ] = {"PTCR" ,64 ,HV_RW , }, +[468 ] = {"HASHKEYR" ,64 ,OS_RW , }, +[469 ] = {"HASHPKEYR" ,64 ,HV_RW , }, +[471 ] = {"HDEXCR" ,64 ,HV_RW , }, +[812 ] = {"DEXCR" ,32 ,RO , }, +[816 ] = {"ASDR" ,64 ,HV_RW ,SPR_INT , }, +[823 ] = {"PSSCR" ,64 ,OS_RW , }, +[828 ] = {"DEXCR" ,64 ,OS_RW , }, +[855 ] = {"PSSCR" ,64 ,HV_RW , }, +}; -static void set_sprs (uint64_t val) +/* SPRs POWER9, POWER10 User Manual */ +static const struct spr sprs_power9_10[1024 ] = { +[276 ] = {"SPRC" ,64 ,HV_RW , }, +[266 ] = {"SPRD" ,64 ,HV_RW , }, +[317 ] = {"TFMR" ,64 ,HV_RW , }, +[799 ] = {"IMC" ,64 ,HV_RW , }, +[850 ] = {"LDBAR" ,64 ,HV_RO , }, +[851 ] = {"MMCRC" ,32 ,HV_RW , }, +[853 ] = {"PMSR" ,32 ,HV_RO , }, +[861 ] = {"L2QOSR" ,64 ,HV_WO , }, +[881 ] = {"TRIG1" ,64 ,OS_WO , }, +[882 ] = {"TRIG2" ,64 ,OS_WO , }, +[884 ] = {"PMCR" ,64 ,HV_RW , }, +[885 ] = {"RWMR" ,64 ,HV_RW , }, +[895 ] = {"WORT" ,64 ,OS_RW , },/* UM says 18-bits! */ +[921 ] = {"TSCR" ,32 ,HV_RW , }, +[922 ] = {"TTR" ,64 ,HV_RW , }, +[1006 ]= {"TRACE" ,64 ,WO , }, +[1008 ]= {"HID" ,64 ,HV_RW , }, +}; + +/* This covers POWER8 and POWER9 PMUs */ +static const struct spr sprs_power_common_pmu[1024 ] = { +[768 ] = {"SIER" ,64 ,RO , }, +[769 ] = {"MMCR2" ,64 ,RW , }, +[770 ] = {"MMCRA" ,64 ,RW , }, +[771 ] = {"PMC1" ,32 ,RW , }, +[772 ] = {"PMC2" ,32 ,RW , }, +[773 ] = {"PMC3" ,32 ,RW , }, +[774 ] = {"PMC4" ,32 ,RW , }, +[775 ] = {"PMC5" ,32 ,RW , }, +[776 ] = {"PMC6" ,32 ,RW , }, +[779 ] = {"MMCR0" ,64 ,RW , }, +[780 ] = {"SIAR" ,64 ,RO , }, +[781 ] = {"SDAR" ,64 ,RO , }, +[782 ] = {"MMCR1" ,64 ,RO , }, +[784 ] = {"SIER" ,64 ,OS_RW , }, +[785 ] = {"MMCR2" ,64 ,OS_RW , }, +[786 ] = {"MMCRA" ,64 ,OS_RW , }, +[787 ] = {"PMC1" ,32 ,OS_RW , }, +[788 ] = {"PMC2" ,32 ,OS_RW , }, +[789 ] = {"PMC3" ,32 ,OS_RW , }, +[790 ] = {"PMC4" ,32 ,OS_RW , }, +[791 ] = {"PMC5" ,32 ,OS_RW , }, +[792 ] = {"PMC6" ,32 ,OS_RW , }, +[795 ] = {"MMCR0" ,64 ,OS_RW , }, +[796 ] = {"SIAR" ,64 ,OS_RW , }, +[797 ] = {"SDAR" ,64 ,OS_RW , }, +[798 ] = {"MMCR1" ,64 ,OS_RW , }, +}; + +static const struct spr sprs_power10_pmu[1024 ] = { +[736 ] = {"SEIR2" ,64 ,RO , }, +[737 ] = {"SEIR3" ,64 ,RO , }, +[738 ] = {"MMCR3" ,64 ,RO , }, +[752 ] = {"SEIR2" ,64 ,OS_RW , }, +[753 ] = {"SEIR3" ,64 ,OS_RW , }, +[754 ] = {"MMCR3" ,64 ,OS_RW , }, +}; + +static struct spr sprs[1024 ]; + +static void setup_sprs (void ) {uint32_t pvr =mfspr (287 );/* Processor Version Register */ +int i; -set_sprs_common (val); +for (i =0 ; i <1024 ; i++) { +if (sprs_common[i].name) { +memcpy (&sprs[i], &sprs_common[i],sizeof (struct spr )); + } + }switch (pvr >>16 ) {case 0x39 :/* PPC970 */ case 0x3C :/* PPC970FX */ case 0x44 :/* PPC970MP */ -set_sprs_book3s_201 (val); +for (i =0 ; i <1024 ; i++) { +if (sprs_power_common[i].name) { +assert (!sprs[i].name); +memcpy (&sprs[i], &sprs_power_common[i],sizeof (struct spr )); + } +if (sprs_201[i].name) { +assert (!sprs[i].name); +memcpy (&sprs[i], &sprs_201[i],sizeof (struct spr )); + } +if (sprs_970_pmu[i].name) { +assert (!sprs[i].name); +memcpy (&sprs[i], &sprs_power_common_pmu[i],sizeof (struct spr )); + } + }break ; +case 0x4b :/* POWER8E */ case 0x4c :/* POWER8NVL */ case 0x4d :/* POWER8 */ -set_sprs_book3s_207 (val); +for (i =0 ; i <1024 ; i++) { +if (sprs_power_common[i].name) { +assert (!sprs[i].name); +memcpy (&sprs[i], &sprs_power_common[i],sizeof (struct spr )); + } +if (sprs_207[i].name) { +assert (!sprs[i].name); +memcpy (&sprs[i], &sprs_207[i],sizeof (struct spr )); + } +if (sprs_tm[i].name) { +assert (!sprs[i].name); +memcpy (&sprs[i], &sprs_tm[i],sizeof (struct spr )); + } +if (sprs_power_common_pmu[i].name) { +assert (!sprs[i].name); +memcpy (&sprs[i], &sprs_power_common_pmu[i],sizeof (struct spr )); + } + }break ; +case 0x4e :/* POWER9 */ -set_sprs_book3s_300 (val); +for (i =0 ; i <1024 ; i++) { +if (sprs_power_common[i].name) { +assert (!sprs[i].name); +memcpy (&sprs[i], &sprs_power_common[i],sizeof (struct spr )); + } +if (sprs_300[i].name) { +assert (!sprs[i].name); +memcpy (&sprs[i], &sprs_300[i],sizeof (struct spr )); + } +if (sprs_tm[i].name) { +assert (!sprs[i].name); +memcpy (&sprs[i], &sprs_tm[i],sizeof (struct spr )); + } +if (sprs_power9_10[i].name) { +assert (!sprs[i].name); +memcpy (&sprs[i], &sprs_power9_10[i],sizeof (struct spr )); + } +if (sprs_power_common_pmu[i].name) { +assert (!sprs[i].name); +memcpy (&sprs[i], &sprs_power_common_pmu[i],sizeof (struct spr )); + } + }break ; -case 0x80 :/* POWER10 */ -set_sprs_book3s_31 (val); + +case 0x80 :/* POWER10 */ +for (i =0 ; i <1024 ; i++) { +if (sprs_power_common[i].name) { +assert (!sprs[i].name); +memcpy (&sprs[i], &sprs_power_common[i],sizeof (struct spr )); + } +if (sprs_31[i].name) { +assert (!sprs[i].name); +memcpy (&sprs[i], &sprs_31[i],sizeof (struct spr )); + } +if (sprs_power9_10[i].name) { +assert (!sprs[i].name); +memcpy (&sprs[i], &sprs_power9_10[i],sizeof (struct spr )); + } +if (sprs_power_common_pmu[i].name) { +assert (!sprs[i].name); +memcpy (&sprs[i], &sprs_power_common_pmu[i],sizeof (struct spr )); + } +if (sprs_power10_pmu[i].name) { +assert (!sprs[i].name); +memcpy (&sprs[i], &sprs_power10_pmu[i],sizeof (struct spr )); + } + }break ; +default : -puts ("Warning: Unknown processor version!\n" ); +memcpy (sprs, sprs_common,sizeof (sprs)); +puts ("Warning: Unknown processor version, falling back to common SPRs!\n" ); +break ; } } -static void get_sprs_common (uint64_t *v) -{ - v[9 ] =mfspr (9 );/* CTR */ -// v[273] = mfspr(273); /* SPRG1 */ /* Used by our exception handler */ - v[274 ] =mfspr (274 );/* SPRG2 */ - v[275 ] =mfspr (275 );/* SPRG3 */ -} - -static void get_sprs_book3s_201 (uint64_t *v) -{ - v[18 ] =mfspr (18 );/* DSISR */ - v[19 ] =mfspr (19 );/* DAR */ - v[136 ] =mfspr (136 );/* CTRL */ - v[256 ] =mfspr (256 );/* VRSAVE */ - v[786 ] =mfspr (786 );/* MMCRA */ - v[795 ] =mfspr (795 );/* MMCR0 */ - v[798 ] =mfspr (798 );/* MMCR1 */ -} - -static void get_sprs_book3s_207 (uint64_t *v) -{ - v[3 ] =mfspr (3 );/* DSCR */ - v[13 ] =mfspr (13 );/* AMR */ - v[17 ] =mfspr (17 );/* DSCR */ - v[18 ] =mfspr (18 );/* DSISR */ - v[19 ] =mfspr (19 );/* DAR */ - v[29 ] =mfspr (29 );/* AMR */ - v[61 ] =mfspr (61 );/* IAMR */ -// v[136] = mfspr(136); /* CTRL */ /* TODO: Needs a fix in KVM */ - v[153 ] =mfspr (153 );/* FSCR */ - v[157 ] =mfspr (157 );/* UAMOR */ - v[159 ] =mfspr (159 );/* PSPB */ - v[256 ] =mfspr (256 );/* VRSAVE */ - v[259 ] =mfspr (259 );/* SPRG3 (read only) */ -// v[272] = mfspr(272); /* SPRG0 */ /* Used by our exception handler */ - v[769 ] =mfspr (769 );/* MMCR2 */ - v[770 ] =mfspr (770 );/* MMCRA */ - v[771 ] =mfspr (771 );/* PMC1 */ - v[772 ] =mfspr (772 );/* PMC2 */ - v[773 ] =mfspr (773 );/* PMC3 */ - v[774 ] =mfspr (774 );/* PMC4 */ - v[775 ] =mfspr (775 );/* PMC5 */ - v[776 ] =mfspr (776 );/* PMC6 */ - v[779 ] =mfspr (779 );/* MMCR0 */ - v[780 ] =mfspr (780 );/* SIAR (read only) */ - v[781 ] =mfspr (781 );/* SDAR (read only) */ - v[782 ] =mfspr (782 );/* MMCR1 (read only) */ - v[784 ] =mfspr (784 );/* SIER */ - v[785 ] =mfspr (785 );/* MMCR2 */ - v[786 ] =mfspr (786 );/* MMCRA */ - v[787 ] =mfspr (787 );/* PMC1 */ - v[788 ] =mfspr (788 );/* PMC2 */ - v[789 ] =mfspr (789 );/* PMC3 */ - v[790 ] =mfspr (790 );/* PMC4 */ - v[791 ] =mfspr (791 );/* PMC5 */ - v[792 ] =mfspr (792 );/* PMC6 */ - v[795 ] =mfspr (795 );/* MMCR0 */ - v[796 ] =mfspr (796 );/* SIAR */ - v[797 ] =mfspr (797 );/* SDAR */ - v[798 ] =mfspr (798 );/* MMCR1 */ - v[800 ] =mfspr (800 );/* BESCRS */ - v[801 ] =mfspr (801 );/* BESCCRSU */ - v[802 ] =mfspr (802 );/* BESCRR */ - v[803 ] =mfspr (803 );/* BESCRRU */ - v[804 ] =mfspr (804 );/* EBBHR */ - v[805 ] =mfspr (805 );/* EBBRR */ - v[806 ] =mfspr (806 );/* BESCR */ - v[815 ] =mfspr (815 );/* TAR */ -} - -static void get_sprs_book3s_300 (uint64_t *v) +static void get_sprs (uint64_t *v) { -get_sprs_book3s_207 (v); - v[48 ] =mfspr (48 );/* PIDR */ - v[144 ] =mfspr (144 );/* TIDR */ - v[823 ] =mfspr (823 );/* PSSCR */ -} +int i; -static void get_sprs_book3s_31 (uint64_t *v) -{ -get_sprs_book3s_207 (v); - v[48 ] =mfspr (48 );/* PIDR */ - v[823 ] =mfspr (823 );/* PSSCR */ +for (i =0 ; i <1024 ; i++) { +if (!(sprs[i].access &SPR_OS_READ )) +continue ; + v[i] =__mfspr (i); + } } -static void get_sprs (uint64_t *v) +static void set_sprs (uint64_t val) { -uint32_t pvr =mfspr (287 );/* Processor Version Register */ - -get_sprs_common (v); +int i; -switch (pvr >>16 ) { -case 0x39 :/* PPC970 */ -case 0x3C :/* PPC970FX */ -case 0x44 :/* PPC970MP */ -get_sprs_book3s_201 (v); -break ; -case 0x4b :/* POWER8E */ -case 0x4c :/* POWER8NVL */ -case 0x4d :/* POWER8 */ -get_sprs_book3s_207 (v); -break ; -case 0x4e :/* POWER9 */ -get_sprs_book3s_300 (v); -break ; -case 0x80 :/* POWER10 */ -get_sprs_book3s_31 (v); -break ; +for (i =0 ; i <1024 ; i++) { +if (!(sprs[i].access &SPR_OS_WRITE )) +continue ; +if (sprs[i].type &SPR_HARNESS ) +continue ; +if (!strcmp (sprs[i].name,"MMCR0" )) { +/* XXX: could use a comment or better abstraction! */ +__mtspr (i, (val &0xfffffffffbab3fffULL ) |0xfa0b2070 ); + }else { +__mtspr (i, val); + } } }
@@ -289,7 +523,9 @@ int main(int argc, char **argv) } } -printf ("Settings SPRs to %#lx...\n" , pat); +setup_sprs (); + +printf ("Setting SPRs to 0x%lx...\n" , pat);set_sprs (pat);memset (before,0 ,sizeof (before));
@@ -301,16 +537,37 @@ int main(int argc, char **argv)migrate_once (); }else {msleep (2000 ); + +/* Taking a dec updates SRR0, SRR1, SPRG1, so don't fail. */ + sprs[26 ].type |=SPR_ASYNC ; + sprs[27 ].type |=SPR_ASYNC ; + sprs[273 ].type |=SPR_ASYNC ; }get_sprs (after);puts ("Checking SPRs...\n" );for (i =0 ; i <1024 ; i++) { -if (before[i] !=0 || after[i] !=0 ) -report (before[i] == after[i], -"SPR %d:\t%#018lx <==> %#018lx" , i, before[i], - after[i]); +bool pass = true; + +if (!(sprs[i].access &SPR_OS_READ )) +continue ; + +if (sprs[i].width ==32 ) { +if (before[i] >>32 ) + pass = false; + } +if (!(sprs[i].type &SPR_ASYNC ) && (before[i] != after[i])) + pass = false; + +if (sprs[i].width ==32 && !(before[i] >>32 ) && !(after[i] >>32 )) +report (pass,"%-10s(%4d):\t 0x%08lx <==> 0x%08lx" , + sprs[i].name, i, + before[i], after[i]); +else +report (pass,"%-10s(%4d):\t0x%016lx <==> 0x%016lx" , + sprs[i].name, i, + before[i], after[i]); }return report_summary ();
Signature · 1 line
2.40.1
PATCH v4 7/12 powerpc/spapr_vpa: Add basic VPA tests
In reply to Nicholas PigginThe VPA is an optional memory structure shared between the hypervisor and operating system, defined by PAPR. This test defines the structure and adds registration, deregistration, and a few simple sanity tests.
[Thanks to Thomas Huth for suggesting many of the test cases.]
--- lib/powerpc/asm/hcall.h | 1 + lib/ppc64/asm/vpa.h | 62 +++++++++++++++ powerpc/Makefile.ppc64 | 2 +- powerpc/spapr_vpa.c | 172 ++++++++++++++++++++++++++++++++++++++++ powerpc/unittests.cfg | 3 + 5 files changed, 239 insertions(+), 1 deletion(-) create mode 100644 lib/ppc64/asm/vpa.h create mode 100644 powerpc/spapr_vpa.c
lib/powerpc/asm/hcall.h +1 -0
@@ -18,6 +18,7 @@#define H_SET_SPRG0 0x24#define H_SET_DABR 0x28#define H_PAGE_INIT 0x2c +#define H_REGISTER_VPA 0xDC#define H_CEDE 0xE0#define H_GET_TERM_CHAR 0x54#define H_PUT_TERM_CHAR 0x58
lib/ppc64/asm/vpa.h new file +62 -0
62 lines not on this page · raw message
powerpc/Makefile.ppc64 +1 -1
@@ -19,7 +19,7 @@ reloc.o = $(TEST_DIR)/reloc64.o OBJDIRS += lib/ppc64 # ppc64 specific tests -tests = +tests = $(TEST_DIR)/spapr_vpa.elf include $(SRCDIR)/$(TEST_DIR)/Makefile.common
powerpc/spapr_vpa.c new file +172 -0
172 lines not on this page · raw message
powerpc/unittests.cfg +3 -0
@@ -39,6 +39,9 @@ groups = selftest [spapr_hcall] file = spapr_hcall.elf +[spapr_vpa] +file = spapr_vpa.elf + [rtas-get-time-of-day] file = rtas.elf timeout = 5
Signature · 1 line
2.40.1
PATCH v4 8/12 powerpc: Expand exception handler vector granularity
In reply to Nicholas PigginException handlers are currently indexed in units of 0x100, but powerpc can have vectors that are aligned to as little as 0x20 bytes. Increase granularity of the handler functions before adding support for those vectors.
---
Since v3:
- Fix typo [Thomas]
lib/powerpc/processor.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)
lib/powerpc/processor.c +11 -5
@@ -16,19 +16,25 @@static struct {void (*func)(struct pt_regs *,void *data);void *data; -} handlers[16 ]; +} handlers[128 ]; +/* +* Exception handlers span from 0x100 to 0x1000 and can have a granularity +* of 0x20 bytes in some cases. Indexing spans 0-0x1000 with 0x20 increments +* resulting in 128 slots. +*/ void handle_exception (int trap,void (*func)(struct pt_regs *,void *),void * data) { -assert (!(trap & ~0xf00 )); +assert (!(trap & ~0xfe0 )); - trap >>=8 ; + trap >>=5 ;if (func && handlers[trap].func) {printf ("exception handler installed twice %#x\n" , trap);abort (); } + handlers[trap].func = func; handlers[trap].data = data; }
@@ -37,9 +43,9 @@ void do_handle_exception(struct pt_regs *regs) {unsigned char v; - v = regs->trap >>8 ; + v = regs->trap >>5 ; -if (v <16 && handlers[v].func) { +if (v <128 && handlers[v].func) { handlers[v].func (regs, handlers[v].data);return ; }
Signature · 1 line
2.40.1
PATCH v4 9/12 powerpc: Add support for more interrupts including HV interrupts
In reply to Nicholas PigginInterrupt vectors were not being populated for all architected interrupt types, which could lead to crashes rather than a message for unhandled interrupts.
0x20 sized vectors require some reworking of the code to fit. This also adds support for HV / HSRR type interrupts which will be used in a later change.
---
Since v3:
- Build fix [Joel]
lib/powerpc/asm/ppc_asm.h | 3 ++ powerpc/cstart64.S | 79 ++++++++++++++++++++++++++++++++------- 2 files changed, 68 insertions(+), 14 deletions(-)
lib/powerpc/asm/ppc_asm.h +3 -0
@@ -35,6 +35,9 @@#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 */
powerpc/cstart64.S +65 -14
116 lines not on this page · raw message
Signature · 1 line
2.40.1
PATCH v4 10/12 powerpc: Discover runtime load address dynamically
In reply to Nicholas PigginThe next change will load the kernels at different addresses depending on test options, so this needs to be reverted back to dynamic discovery.
--- powerpc/cstart64.S | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-)
powerpc/cstart64.S +14 -5
@@ -33,9 +33,14 @@ start: * We were loaded at QEMU's kernel load address, but we're not * allowed to link there due to how QEMU deals with linker VMAs, * so we just linked at zero. This means the first thing to do is - * to find our stack and toc, and then do a relocate. + * to find our stack and toc, and then do a relocate. powernv and + * pseries load addresses are not the same, so find the address + * dynamically: */ - LOAD_REG_IMMEDIATE(r31, SPAPR_KERNEL_LOAD_ADDR) + bl 0f +0: mflr r31 + subi r31, r31, 0b - start /* QEMU's kernel load address */ + ld r1, (p_stack - start)(r31) ld r2, (p_toc - start)(r31) add r1, r1, r31
@@ -114,8 +119,11 @@ p_toc: .llong tocptr p_dyn: .llong dynamic_start .text +start_text: .align 3 +p_toc_text: .llong tocptr +.align 3 .globl hcall hcall: sc 1
@@ -185,9 +193,10 @@ call_handler: std r0,_CCR(r1) /* restore TOC pointer */ - - LOAD_REG_IMMEDIATE(r31, SPAPR_KERNEL_LOAD_ADDR) - ld r2, (p_toc - start)(r31) + bl 0f +0: mflr r31 + subi r31, r31, 0b - start_text + ld r2, (p_toc_text - start_text)(r31) /* FIXME: build stack frame */
Signature · 1 line
2.40.1
PATCH v4 11/12 powerpc: Support powernv machine with QEMU TCG
In reply to Nicholas PigginThis is a basic first pass at powernv support using OPAL (skiboot) firmware.
The ACCEL is a bit clunky, defaulting to kvm for powernv machine, which isn't right and has to be manually overridden. It also does not yet run in the run_tests.sh batch process, more work is needed to exclude certain tests (e.g., rtas) and adjust parameters (e.g., increase memory size) to allow powernv to work. For now it can run single test cases.
---
Since v3:
- Typo fix [Thomas]
lib/powerpc/asm/ppc_asm.h | 5 +++ lib/powerpc/asm/processor.h | 10 +++++ lib/powerpc/hcall.c | 4 +- lib/powerpc/io.c | 27 +++++++++++++- lib/powerpc/io.h | 6 +++ lib/powerpc/processor.c | 10 +++++ lib/powerpc/setup.c | 8 ++-- lib/ppc64/asm/opal.h | 15 ++++++++ lib/ppc64/opal-calls.S | 46 +++++++++++++++++++++++ lib/ppc64/opal.c | 74 +++++++++++++++++++++++++++++++++++++ powerpc/Makefile.ppc64 | 2 + powerpc/cstart64.S | 7 ++++ powerpc/run | 35 ++++++++++++++++-- 13 files changed, 238 insertions(+), 11 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/ppc_asm.h +5 -0
@@ -39,7 +39,12 @@#define SPR_HSRR1 0x13B/* 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 SPR_HSRR0 0x13A +#define SPR_HSRR1 0x13B +#endif /* _ASMPOWERPC_PPC_ASM_H */
lib/powerpc/asm/processor.h +10 -0
@@ -3,6 +3,7 @@#include <libcflat.h> #include <asm/ptrace.h> +#include <asm/ppc_asm.h> #ifndef __ASSEMBLY__void handle_exception (int trap,void (*func)(struct pt_regs *,void *),void *);
@@ -43,6 +44,15 @@ static inline void mtmsr(uint64_t msr) asmvolatile ("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 !!(mfmsr () & (1ULL <<MSR_HV_BIT )); +} +static inline uint64_t get_tb (void ) {return mfspr (SPR_TB );
lib/powerpc/hcall.c +2 -2
@@ -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
@@ -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
@@ -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 +10 -0
@@ -71,6 +71,16 @@ void sleep_tb(uint64_t cycles) {uint64_t start, end, now; +if (machine_is_powernv ()) { +/* +* 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;
lib/powerpc/setup.c +5 -3
@@ -18,6 +18,7 @@#include <argv.h> #include <asm/setup.h> #include <asm/page.h> +#include <asm/processor.h> #include <asm/hcall.h> #include "io.h"
@@ -97,12 +98,13 @@ static void cpu_init(void) tb_hz = params.tb_hz;/* Interrupt Endianness */ - +if (!machine_is_powernv ()) {#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)
lib/ppc64/asm/opal.h new file +15 -0
@@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +#ifndef _ASMPPC64_HCALL_H_ +#define _ASMPPC64_HCALL_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 +46 -0
46 lines not on this page · raw message
lib/ppc64/opal.c new file +74 -0
74 lines not on this page · raw message
powerpc/Makefile.ppc64 +2 -0
@@ -17,6 +17,8 @@ cstart.o = $(TEST_DIR)/cstart64.o reloc.o = $(TEST_DIR)/reloc64.o OBJDIRS += lib/ppc64 +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
@@ -92,6 +92,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 +31 -4
@@ -1,5 +1,14 @@ #!/usr/bin/env bash +get_qemu_machine () +{ + if [ "$MACHINE" ]; then + echo $MACHINE + else + echo pseries + fi +} + if [ -z "$KUT_STANDALONE" ]; then if [ ! -f config.mak ]; then echo "run ./configure && make first. See ./configure -h"
@@ -12,17 +21,35 @@ fi ACCEL=$(get_qemu_accelerator) || exit $? +MACHINE=$(get_qemu_machine) || + exit $? + +if [[ "$MACHINE" == "powernv"* ]] && [ "$ACCEL" = "kvm" ]; then + echo "PowerNV machine does not support KVM. ACCEL=tcg must be specified." + exit 2 +fi + qemu=$(search_qemu_binary) || exit $? -if ! $qemu -machine '?' 2>&1 | grep 'pseries' > /dev/null; then - echo "$qemu doesn't support pSeries ('-machine pseries'). Exiting." +if ! $qemu -machine '?' 2>&1 | grep $MACHINE > /dev/null; then + echo "$qemu doesn't support '-machine $MACHINE'. Exiting." exit 2 fi -M='-machine pseries' +M="-machine $MACHINE" M+=",accel=$ACCEL" -command="$qemu -nodefaults $M -bios $FIRMWARE" +B="" +if [[ "$MACHINE" == "pseries"* ]] ; then + B+="-bios $FIRMWARE" +fi + +D="" +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+=" -display none -serial stdio -kernel" command="$(migration_cmd) $(timeout_cmd) $command"
Signature · 1 line
2.40.1
PATCH v4 12/12 powerpc/sprs: Test hypervisor registers on powernv machine
In reply to Nicholas PigginThis 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
@@ -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, }, /* At least 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 (machine_is_powernv ()) +return !!(sprs[spr].access &SPR_HV_READ ); +else +return !!(sprs[spr].access &SPR_OS_READ ); +} + +static bool spr_write_perms (int spr) +{ +if (machine_is_powernv ()) +return !!(sprs[spr].access &SPR_HV_WRITE ); +else +return !!(sprs[spr].access &SPR_OS_WRITE ); +} +static void setup_sprs (void ) {uint32_t pvr =mfspr (287 );/* Processor Version Register */
@@ -466,7 +482,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); }
@@ -477,8 +493,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 ;if (!strcmp (sprs[i].name,"MMCR0" )) {
@@ -550,7 +567,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.40.1
Quoted 3 lines · Nicholas Piggin
Posting again, a couple of patches were merged and accounted for review comments from last time.
I saw some failures in the spr tests running on a power9 powernv system:
$ TESTNAME=sprs TIMEOUT=90s ACCEL= ./powerpc/run powerpc/sprs.elf -smp 1 |grep FAIL FAIL: WORT ( 895): 0x00000000c0deba80 <==> 0x0000000000000000
$ MIGRATION=yes TESTNAME=sprs-migration TIMEOUT=90s ACCEL= ./powerpc/run powerpc/sprs.elf -smp 1 -append '-w' | grep FAIL FAIL: SRR0 ( 26): 0xcafefacec0debabc <==> 0x0000000000402244 FAIL: SRR1 ( 27): 0xc0000006409ebab6 <==> 0x8000000000001001 FAIL: CTRL ( 136): 0x00000000 <==> 0x00008001 FAIL: WORT ( 895): 0x00000000c0deba80 <==> 0x0000000000000000 FAIL: PIR (1023): 0x00000010 <==> 0x00000049
Linux 6.2.0-20-generic
QEMU emulator version 7.2.0 (Debian 1:7.2+dfsg-5ubuntu2)
On a power8 powernv:
MIGRATION=yes TESTNAME=sprs-migration TIMEOUT=90s ACCEL= ./powerpc/run powerpc/sprs.elf -smp 1 -append '-w' |grep FAIL
FAIL: SRR0 ( 26): 0xcafefacec0debabc <==> 0x0000000000402234
FAIL: SRR1 ( 27): 0xc0000006409ebab6 <==> 0x8000000000001000
FAIL: CTRL ( 136): 0x00000000 <==> 0x00008001
FAIL: PIR (1023): 0x00000060 <==> 0x00000030
Linux 5.4.0-146-generic
QEMU emulator version 4.2.1 (Debian 1:4.2-3ubuntu6.26)
Cheers,
Joel
Quoted 51 lines
Thanks,
NickNicholas Piggin (12):
powerpc: Report instruction address and MSR in unhandled exception
error
powerpc: Add some checking to exception handler install
powerpc: AbstractH_CEDEcalls into a sleep functions
powerpc: Add ISA v3.1 (POWER10) support to SPR test
powerpc: Extract some common helpers and defines to headers powerpc/sprs: Specify SPRs with data rather than code powerpc/spapr_vpa: Add basic VPA tests
powerpc: Expand exception handler vector granularity
powerpc: Add support for more interrupts including HV interrupts
powerpc: Discover runtime load address dynamically
powerpc: Support powernv machine with QEMU TCG powerpc/sprs: Test hypervisor registers on powernv machinelib/powerpc/asm/handlers.h | 2 +- lib/powerpc/asm/hcall.h | 1 + lib/powerpc/asm/ppc_asm.h | 9 + lib/powerpc/asm/processor.h | 55 ++- lib/powerpc/handlers.c | 10 +- lib/powerpc/hcall.c | 4 +- lib/powerpc/io.c | 27 +- lib/powerpc/io.h | 6 + lib/powerpc/processor.c | 79 ++++- lib/powerpc/setup.c | 8 +- lib/ppc64/asm/opal.h | 15 + lib/ppc64/asm/vpa.h | 62 ++++ lib/ppc64/opal-calls.S | 46 +++ lib/ppc64/opal.c | 74 +++++ powerpc/Makefile.ppc64 | 4 +- powerpc/cstart64.S | 105 ++++-- powerpc/run | 35 +- powerpc/spapr_hcall.c | 9 +- powerpc/spapr_vpa.c | 172 ++++++++++ powerpc/sprs.c | 645 ++++++++++++++++++++++++++---------- powerpc/tm.c | 20 +- powerpc/unittests.cfg | 3 + 22 files changed, 1133 insertions(+), 258 deletions(-) create mode 100644 lib/ppc64/asm/opal.h create mode 100644 lib/ppc64/asm/vpa.h create mode 100644 lib/ppc64/opal-calls.S create mode 100644 lib/ppc64/opal.c create mode 100644 powerpc/spapr_vpa.c--
2.40.1
Quoted 10 lines · Joel Stanley
Quoted 3 lines · Nicholas Piggin
Posting again, a couple of patches were merged and accounted for review comments from last time.
I saw some failures in the spr tests running on a power9 powernv system:
$ TESTNAME=sprs TIMEOUT=90s ACCEL= ./powerpc/run powerpc/sprs.elf -smp 1 |grep FAIL FAIL: WORT ( 895): 0x00000000c0deba80 <==> 0x0000000000000000
This is just TCG machine? I'm not sure why WORT fails, AFAIKS it's the same on POWER8 and doesn't do anything just a simple register. I think on real hardware WORT may not have any bits implemented on POWER9 though.
Quoted 11 lines
$ MIGRATION=yes TESTNAME=sprs-migration TIMEOUT=90s ACCEL= ./powerpc/run powerpc/sprs.elf -smp 1 -append '-w' | grep FAIL FAIL: SRR0 ( 26): 0xcafefacec0debabc <==> 0x0000000000402244 FAIL: SRR1 ( 27): 0xc0000006409ebab6 <==> 0x8000000000001001 FAIL: CTRL ( 136): 0x00000000 <==> 0x00008001 FAIL: WORT ( 895): 0x00000000c0deba80 <==> 0x0000000000000000 FAIL: PIR (1023): 0x00000010 <==> 0x00000049Linux 6.2.0-20-generic
QEMU emulator version 7.2.0 (Debian 1:7.2+dfsg-5ubuntu2)
Quoted 8 lines
On a power8 powernv:
MIGRATION=yes TESTNAME=sprs-migration TIMEOUT=90s ACCEL= ./powerpc/run powerpc/sprs.elf -smp 1 -append '-w' |grep FAIL
FAIL: SRR0 ( 26):0xcafefacec0debabc<==>0x0000000000402234
FAIL: SRR1 ( 27):0xc0000006409ebab6<==>0x8000000000001000
FAIL: CTRL ( 136):0x00000000<==>0x00008001
FAIL: PIR (1023):0x00000060<==>0x00000030
Hmm, seems we take some interrupt over migration test that is not accounted for (could check the address in SRR0 to see where it is). Either need to prevent that interrupt or avoid failing on SRR0/1 on this test.
Interesting about CTRL, I wonder if that not migrating correctly. PIR looks like a migration issue as well, it can't be changed so destination CPU has got a different PIR. I would be inclined to leave those as failing to remind us to look into them.
I'll take a look at the others though.
Thanks,
Nick
Quoted 9 lines · Nicholas Piggin
Quoted 7 lines · Joel Stanley
Quoted 3 lines · Nicholas Piggin
Posting again, a couple of patches were merged and accounted for review comments from last time.
I saw some failures in the spr tests running on a power9 powernv system:
Quoted 8 lines
Quoted 3 lines
$ TESTNAME=sprs TIMEOUT=90s ACCEL= ./powerpc/run powerpc/sprs.elf -smp 1 |grep FAIL FAIL: WORT ( 895): 0x00000000c0deba80 <==> 0x0000000000000000This is just TCG machine? I'm not sure why WORT fails, AFAIKS it's the same on POWER8 and doesn't do anything just a simple register. I think on real hardware WORT may not have any bits implemented on POWER9 though.
Yeah, just the TCG machine. Now that you point it out all of the failures I reported are for ACCEL=<blank>, so they are running in tcg mode.
run_migration timeout -k 1s --foreground 90s /usr/bin/qemu-system-ppc64 -nodefaults -machine pseries,accel=tcg -bios powerpc/boot_rom.bin -display none -serial stdio -kernel powerpc/sprs.elf -smp 1 -append -w # -initrd /tmp/tmp.61XhbvCGcb
Quoted 35 lines
Quoted 12 lines
$ MIGRATION=yes TESTNAME=sprs-migration TIMEOUT=90s ACCEL= ./powerpc/run powerpc/sprs.elf -smp 1 -append '-w' | grep FAIL FAIL: SRR0 ( 26): 0xcafefacec0debabc <==> 0x0000000000402244 FAIL: SRR1 ( 27): 0xc0000006409ebab6 <==> 0x8000000000001001 FAIL: CTRL ( 136): 0x00000000 <==> 0x00008001 FAIL: WORT ( 895): 0x00000000c0deba80 <==> 0x0000000000000000 FAIL: PIR (1023): 0x00000010 <==> 0x00000049Linux 6.2.0-20-generic
QEMU emulator version 7.2.0 (Debian 1:7.2+dfsg-5ubuntu2)Quoted 8 lines
On a power8 powernv:
MIGRATION=yes TESTNAME=sprs-migration TIMEOUT=90s ACCEL= ./powerpc/run powerpc/sprs.elf -smp 1 -append '-w' |grep FAIL
FAIL: SRR0 ( 26):0xcafefacec0debabc<==>0x0000000000402234
FAIL: SRR1 ( 27):0xc0000006409ebab6<==>0x8000000000001000
FAIL: CTRL ( 136):0x00000000<==>0x00008001
FAIL: PIR (1023):0x00000060<==>0x00000030Hmm, seems we take some interrupt over migration test that is not accounted for (could check the address in SRR0 to see where it is). Either need to prevent that interrupt or avoid failing on SRR0/1 on this test.
Interesting about CTRL, I wonder if that not migrating correctly. PIR looks like a migration issue as well, it can't be changed so destination CPU has got a different PIR. I would be inclined to leave those as failing to remind us to look into them.
I'll take a look at the others though.
Thanks,
Nick
Re: [kvm-unit-tests v4 01/12] powerpc: Report instruction address and MSR in unhandled exception error
In reply to Nicholas PigginQuoted 13 lines · Nicholas Piggin
Signed-off-by Nicholas Piggin <[email protected]>---
Since v3:
- New patchlib/powerpc/processor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)lib/powerpc/processor.c +0
-0
lib/powerpc/processor.c void do_handle_exception(struct pt_regs *regs) · line 41
Quoted 5 lines
lib/powerpc/processor.c +1
-1@@ -38,7 +38,7 @@ void do_handle_exception(struct pt_regs *regs)return ; } -printf ("unhandled cpu exception %#lx\n" , regs->trap); +printf ("unhandled cpu exception %#lx at NIA:0x%016lx MSR:0x%016lx\n" , regs->trap, regs->nip, regs->msr);
<bikeshedding> Why NIA and not NIP ? </bikeshedding>
Thomas
Re: [kvm-unit-tests v4 02/12] powerpc: Add some checking to exception handler install
In reply to Nicholas PigginQuoted 25 lines · Nicholas Piggin
Check to ensure exception handlers are not being overwritten or invalid exception numbers are used.
Signed-off-by Nicholas Piggin <[email protected]>---
Since v3:
- Simplified code as suggested by Thomas.lib/powerpc/processor.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)lib/powerpc/processor.c +2
-2@@ -19,12 +19,16 @@ static struct {void handle_exception (int trap,void (*func)(struct pt_regs *,void *),void * data) { +assert (!(trap & ~0xf00 )); + trap >>=8 ; -if (trap <16 ) { - handlers[trap].func = func;
lib/powerpc/processor.c static struct { · line 34
Quoted 10 lines
lib/powerpc/processor.c +5
-1- handlers[trap].data = data; +if (func && handlers[trap].func) { +printf ("exception handler installed twice %#x\n" , trap); +abort (); } + handlers[trap].func = func; + handlers[trap].data = data; }void do_handle_exception (struct pt_regs *regs)
Re: [kvm-unit-tests v4 03/12] powerpc: Abstract H_CEDE calls into a sleep functions
In reply to Nicholas PigginQuoted 210 lines · Nicholas Piggin
This consolidates several implementations, and it no longer leaves MSR[EE] enabled after the decrementer interrupt is handled, but rather disables it on return.
The handler no longer allows a continuous ticking, but rather dec has to be re-armed and EE re-enabled (e.g., via
H_CEDEhcall) each time.Signed-off-by Nicholas Piggin <[email protected]>--- lib/powerpc/asm/handlers.h | 2 +- lib/powerpc/asm/ppc_asm.h | 1 + lib/powerpc/asm/processor.h | 7 ++++++ lib/powerpc/handlers.c | 10 ++++----- lib/powerpc/processor.c | 43 +++++++++++++++++++++++++++++++++++++ powerpc/sprs.c | 6 +----- powerpc/tm.c | 20 +---------------- 7 files changed, 58 insertions(+), 31 deletions(-)lib/powerpc/asm/handlers.h +1
-1@@ -3,6 +3,6 @@#include <asm/ptrace.h> -void dec_except_handler (struct pt_regs *regs,void *data); +void dec_handler_oneshot (struct pt_regs *regs,void *data);#endif /* _ASMPOWERPC_HANDLERS_H_ */ lib/powerpc/asm/ppc_asm.h +1
-0@@ -36,6 +36,7 @@#endif /* __BYTE_ORDER__ */ /* Machine State Register definitions: */ +#define MSR_EE_BIT 15/* External Interrupts Enable */ #define MSR_SF_BIT 63/* 64-bit mode */ #endif /* _ASMPOWERPC_PPC_ASM_H */ lib/powerpc/asm/processor.h +7
-0@@ -20,6 +20,8 @@ static inline uint64_t get_tb(void)extern void delay (uint64_t cycles);extern void udelay (uint64_t us); +extern void sleep_tb (uint64_t cycles); +extern void usleep (uint64_t us);static inline void mdelay (uint64_t ms) {@@ -27,4 +29,9 @@ static inline void mdelay(uint64_t ms) udelay(1000); } +static inline void msleep (uint64_t ms) +{ +usleep (ms *1000 ); +} +#endif /* _ASMPOWERPC_PROCESSOR_H_ */ lib/powerpc/handlers.c +4
-6@@ -9,15 +9,13 @@#include <libcflat.h> #include <asm/handlers.h> #include <asm/ptrace.h> +#include <asm/ppc_asm.h> /* * Generic handler for decrementer exceptions (0x900) -* Just reset the decrementer back to the value specified when registering the -* handler +* Return with MSR[EE] disabled. */ -void dec_except_handler(struct pt_regs *regs __unused, void *data) +void dec_handler_oneshot (struct pt_regs *regs,void *data) { -uint64_t dec = *((uint64_t *) data); - - asmvolatile ("mtdec %0" : :"r" (dec)); + regs->msr &= ~(1UL <<MSR_EE_BIT ); }lib/powerpc/processor.c +43
-0@@ -10,6 +10,8 @@#include <asm/ptrace.h> #include <asm/setup.h> #include <asm/barrier.h> +#include <asm/hcall.h> +#include <asm/handlers.h> static struct { void (*func)(struct pt_regs *, void *data);@@ -58,3 +60,44 @@ void udelay(uint64_t us) {delay ((us * tb_hz) /1000000 ); } + +void sleep_tb (uint64_t cycles) +{ +uint64_t start, end, now; + + start = now =get_tb (); + end = start + cycles; + +while (end > now) { +uint64_t left = end - now; + +/* TODO: Could support large decrementer */ +if (left >0x7fffffff ) + left =0x7fffffff ; + +/* DEC won't fire until H_CEDE is called because EE=0 */ + asmvolatile ("mtdec %0" : :"r" (left)); +handle_exception (0x900 , &dec_handler_oneshot,NULL ); +/* +* H_CEDE is called with MSR[EE] clear and enables it as part +* of the hcall, returning with EE enabled. The dec interrupt +* is then taken immediately and the handler disables EE. +* +* If H_CEDE returned for any other interrupt than dec +* expiring, that is considered an unhandled interrupt and +* the test case would be stopped. +*/ +if (hcall (H_CEDE ) !=H_SUCCESS ) { +printf ("H_CEDE failed\n" ); +abort (); + } +handle_exception (0x900 ,NULL ,NULL ); + + now =get_tb (); + } +} + +void usleep (uint64_t us) +{ +sleep_tb ((us * tb_hz) /1000000 ); +}powerpc/sprs.c +1
-5@@ -254,7 +254,6 @@ int main(int argc, char **argv)0x1234567890ABCDEFULL ,0xFEDCBA0987654321ULL , -1ULL, }; -static uint64_t decr =0x7FFFFFFF ;/* Max value */ for (i =1 ; i < argc; i++) {if (!strcmp (argv[i],"-w" )) {@@ -288,10 +287,7 @@ int main(int argc, char **argv)if (pause) {migrate_once (); }else { -puts ("Sleeping...\n" ); -handle_exception (0x900 , &dec_except_handler, &decr); - asmvolatile ("mtdec %0" : :"r" (0x3FFFFFFF )); -hcall (H_CEDE ); +msleep (2000 ); }get_sprs (after);powerpc/tm.c +0
-15@@ -48,17 +48,6 @@ static int count_cpus_with_tm(void)return available; } -static int h_cede (void ) -{ - register uint64_t r3 asm("r3") = H_CEDE; - - asmvolatile ("sc 1" :"+r" (r3) : - :"r0" ,"r4" ,"r5" ,"r6" ,"r7" ,"r8" ,"r9" , -"r10" ,"r11" ,"r12" ,"xer" ,"ctr" ,"cc" ); - -return r3; -} -/* * Enable transactional memory * Returns: FALSE - Failure @@ -95,14 +84,10 @@ static bool enable_tm(void)static void test_h_cede_tm (int argc,char **argv) {int i; -static uint64_t decr =0x3FFFFF ;/* ~10ms */ if (argc >2 )report_abort ("Unsupported argument: '%s'" , argv[2 ]); -handle_exception (0x900 , &dec_except_handler, &decr); - asmvolatile ("mtdec %0" : :"r" (decr)); -if (!start_all_cpus (halt,0 ))report_abort ("Failed to start secondary cpus" );
powerpc/tm.c static void test_h_cede_tm(int argc, char **argv) · line 109
Quoted 9 lines
powerpc/tm.c +1
-4@@ -120,10 +105,7 @@ static void test_h_cede_tm(int argc, char **argv) "bf 2,1b" : : : "cr0"); for (i = 0; i < 500; i++) { -uint64_t rval =h_cede (); - -if (rval !=H_SUCCESS ) -break ; +msleep (10 );mdelay (5 );
msleep() directly followed by an mdelay() looks weird now. Do we still need the mdelay()? Or could we maybe at least get a comment here why there are now two different delaying calls here?
Thomas
Quoted 2 lines
powerpc/tm.c +0
-0}
Quoted 2 lines · Nicholas Piggin
Posting again, a couple of patches were merged and accounted for review comments from last time.
Sorry for not being very responsive ... it's been a busy month.
Anyway, I've now merged the first 5 patches and the VPA test since they look fine to me.
As Joel already wrote, there is an issue with the sprs patch, I also get an error with the PIR register on the P8 box that I have access to as soon as I apply the "Specify SPRs with data rather than code" patch. It would be good to get that problem resolved before merging the remaining patches...
Thomas
Quoted 5 lines · Thomas Huth
Quoted 2 lines · Nicholas Piggin
Posting again, a couple of patches were merged and accounted for review comments from last time.
Sorry for not being very responsive ... it's been a busy month.
Hah that's okay, I'll say the same thing. I was meaning to get back to Joel and your comments but lots on all of a sudden, sigh.
Quoted 7 lines
Anyway, I've now merged the first 5 patches and the VPA test since they look fine to me.
As Joel already wrote, there is an issue with the sprs patch, I also get an error with the PIR register on the P8 box that I have access to as soon as I apply the "Specify SPRs with data rather than code" patch. It would be good to get that problem resolved before merging the remaining patches...
Thanks for this, yes needs a bit more polish. I'll try to get to it now that qemu is mostly done for 8.1.
Thanks,
Nick