s390x patches
Hi Paolo,
The following changes since commit 82147b77199bbfec2c61c97685cfb34f3f97c889:
fw_cfg: avoid index out of bounds (2020-07-30 17:57:55 -0400)
are available in the Git repository at:
https://github.com/frankjaa/kvm-unit-tests.git tags/s390x-2020-31-07
for you to fetch changes up to c2f4799a861993b82950b9e5a3a44fc65ba05ec6:
s390x: fix inline asm on gcc10 (2020-07-31 04:35:33 -0400)
----------------------------------------------------------------
* IO tests from Pierre
* GCC 10 compile fix from Claudio
* CPU model test fix from Thomas
----------------------------------------------------------------
Claudio Imbrenda (1):
s390x: fix inline asm on gcc10
Pierre Morel (9):
s390x: saving regs for interrupts
s390x: I/O interrupt registration
s390x: export the clock get_clock_ms() utility
s390x: clock and delays calculations
s390x: define function to wait for interrupt
s390x: Library resources for CSS tests
s390x: css: stsch, enumeration test
s390x: css: msch, enable test
s390x: css: ssch/tsch with sense and interrupt
Thomas Huth (1):
s390x/cpumodel: The missing DFP facility on TCG is expected
lib/s390x/asm/arch_def.h | 14 ++ lib/s390x/asm/cpacf.h | 5 +- lib/s390x/asm/time.h | 50 ++++++ lib/s390x/css.h | 294 +++++++++++++++++++++++++++++++++++ lib/s390x/css_dump.c | 152 +++++++++++++++++++ lib/s390x/css_lib.c | 320 +++++++++++++++++++++++++++++++++++++++ lib/s390x/interrupt.c | 23 ++- lib/s390x/interrupt.h | 8 + lib/s390x/vm.c | 46 ++++++ lib/s390x/vm.h | 14 ++ s390x/Makefile | 4 + s390x/cpumodel.c | 19 ++- s390x/css.c | 150 ++++++++++++++++++ s390x/cstart64.S | 41 ++++- s390x/emulator.c | 25 +-- s390x/intercept.c | 11 +- s390x/unittests.cfg | 4 + 17 files changed, 1147 insertions(+), 33 deletions(-) create mode 100644 lib/s390x/asm/time.h create mode 100644 lib/s390x/css.h create mode 100644 lib/s390x/css_dump.c create mode 100644 lib/s390x/css_lib.c create mode 100644 lib/s390x/interrupt.h create mode 100644 lib/s390x/vm.c create mode 100644 lib/s390x/vm.h create mode 100644 s390x/css.c
Signature · 1 line
2.25.4
[kvm-unit-tests GIT PULL 01/11] s390x/cpumodel: The missing DFP facility on TCG is expected
From: Thomas Huth <[email protected]>
When running the kvm-unit-tests with TCG on s390x, the cpumodel test always reports the error about the missing DFP (decimal floating point) facility. This is kind of expected, since DFP is not required for running Linux and thus nobody is really interested in implementing this facility in TCG. Thus let's mark this as an expected error instead, so that we can run the kvm-unit-tests also with TCG without getting test failures that we do not care about.
Message-Id: <[email protected]>
--- lib/s390x/vm.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ lib/s390x/vm.h | 14 ++++++++++++++ s390x/Makefile | 1 + s390x/cpumodel.c | 19 +++++++++++++------ 4 files changed, 74 insertions(+), 6 deletions(-) create mode 100644 lib/s390x/vm.c create mode 100644 lib/s390x/vm.h
lib/s390x/vm.c new file +46 -0
@@ -0,0 +1,46 @@ +/* +* Functions to retrieve VM-specific information +* +* Copyright (c) 2020 Red Hat Inc +* +* Authors: +* Thomas Huth <[email protected]> +* +* SPDX-License-Identifier: LGPL-2.1-or-later +*/ + +#include <libcflat.h> +#include <alloc_page.h> +#include <asm/arch_def.h> +#include "vm.h" + +/** +* Detect whether we are running with TCG (instead of KVM) +*/ +bool vm_is_tcg (void ) +{ +const char qemu_ebcdic[] = {0xd8 ,0xc5 ,0xd4 ,0xe4 }; +static bool initialized = false; +static bool is_tcg = false; +uint8_t *buf; + +if (initialized) +return is_tcg; + + buf =alloc_page (); +if (!buf) +return false; + +if (stsi (buf,1 ,1 ,1 )) + goto out; + +/* +* If the manufacturer string is "QEMU" in EBCDIC, then we +* are on TCG (otherwise the string is "IBM" in EBCDIC) +*/ + is_tcg = !memcmp (&buf[32 ], qemu_ebcdic,sizeof (qemu_ebcdic)); + initialized = true; +out: +free_page (buf); +return is_tcg; +}
lib/s390x/vm.h new file +14 -0
@@ -0,0 +1,14 @@ +/* +* Functions to retrieve VM-specific information +* +* Copyright (c) 2020 Red Hat Inc +* +* SPDX-License-Identifier: LGPL-2.1-or-later +*/ + +#ifndef S390X_VM_H +#define S390X_VM_H + +bool vm_is_tcg (void ); + +#endif /* S390X_VM_H */
s390x/Makefile +1 -0
@@ -51,6 +51,7 @@ cflatobjs += lib/s390x/sclp-console.o cflatobjs += lib/s390x/interrupt.o cflatobjs += lib/s390x/mmu.o cflatobjs += lib/s390x/smp.o +cflatobjs += lib/s390x/vm.o OBJDIRS += lib/s390x
s390x/cpumodel.c +13 -6
@@ -11,14 +11,19 @@*/ #include <asm/facility.h> +#include <vm.h> -static int dep[][2 ] = { +static struct { +int facility; +int implied; +bool expected_tcg_fail; +} dep[] = {/* from SA22-7832-11 4-98 facility indications */ {4 ,3 }, {5 ,3 }, {5 ,4 }, {19 ,18 }, - {37 ,42 }, + {37 ,42 , true },/* TCG does not have DFP and won't get it soon */ {43 ,42 }, {73 ,49 }, {134 ,129 },
@@ -46,11 +51,13 @@ int main(void)report_prefix_push ("dependency" );for (i =0 ; i <ARRAY_SIZE (dep); i++) { -if (test_facility (dep[i][0 ])) { -report (test_facility (dep[i][1 ]),"%d implies %d" , - dep[i][0 ], dep[i][1 ]); +if (test_facility (dep[i].facility)) { +report_xfail (dep[i].expected_tcg_fail &&vm_is_tcg (), +test_facility (dep[i].implied), +"%d implies %d" , + dep[i].facility, dep[i].implied); }else { -report_skip ("facility %d not present" , dep[i][0 ]); +report_skip ("facility %d not present" , dep[i].facility); } }report_prefix_pop ();
Signature · 1 line
2.25.4
[kvm-unit-tests GIT PULL 02/11] s390x: saving regs for interrupts
In reply to Janosch FrankFrom: Pierre Morel <[email protected]>
If we use multiple source of interrupts, for example, using SCLP console to print information while using I/O interrupts, we need to have a re-entrant register saving interruption handling.
Instead of saving at a static memory address, let's save the base registers, the floating point registers and the floating point control register on the stack in case of I/O interrupts
Note that we keep the static register saving to recover from the RESET tests.
Message-Id: <[email protected]>
--- s390x/cstart64.S | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-)
s390x/cstart64.S +39 -2
@@ -118,6 +118,43 @@ memsetxc: lmg %r0, %r15, GEN_LC_SW_INT_GRS .endm +/* Save registers on the stack (r15), so we can have stacked interrupts. */ + .macro SAVE_REGS_STACK + /* Allocate a stack frame for 15 general registers */ + slgfi %r15, 15 * 8 + /* Store registers r0 to r14 on the stack */ + stmg %r0, %r14, 0(%r15) + /* Allocate a stack frame for 16 floating point registers */ + /* The size of a FP register is the size of an double word */ + slgfi %r15, 16 * 8 + /* Save fp register on stack: offset to SP is multiple of reg number */ + .irp i, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 + std \i, \i * 8(%r15) + .endr + /* Save fpc, but keep stack aligned on 64bits */ + slgfi %r15, 8 + efpc %r0 + stg %r0, 0(%r15) + .endm + +/* Restore the register in reverse order */ + .macro RESTORE_REGS_STACK + /* Restore fpc */ + lfpc 0(%r15) + algfi %r15, 8 + /* Restore fp register from stack: SP still where it was left */ + /* and offset to SP is a multiple of reg number */ + .irp i, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 + ld \i, \i * 8(%r15) + .endr + /* Now that we're done, rewind the stack pointer by 16 double word */ + algfi %r15, 16 * 8 + /* Load the registers from stack */ + lmg %r0, %r14, 0(%r15) + /* Rewind the stack by 15 double word */ + algfi %r15, 15 * 8 + .endm + .section .text /* * load_reset calling convention:
@@ -185,9 +222,9 @@ mcck_int: lpswe GEN_LC_MCCK_OLD_PSW io_int: - SAVE_REGS + SAVE_REGS_STACK brasl %r14, handle_io_int - RESTORE_REGS + RESTORE_REGS_STACK lpswe GEN_LC_IO_OLD_PSW svc_int:
Signature · 1 line
2.25.4
[kvm-unit-tests GIT PULL 03/11] s390x: I/O interrupt registration
In reply to Janosch FrankFrom: Pierre Morel <[email protected]>
Let's make it possible to add and remove a custom io interrupt handler, that can be used instead of the normal one.
Message-Id: <[email protected]>
--- lib/s390x/interrupt.c | 23 ++++++++++++++++++++++- lib/s390x/interrupt.h | 8 ++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 lib/s390x/interrupt.h
lib/s390x/interrupt.c +22 -1
@@ -10,9 +10,9 @@* under the terms of the GNU Library General Public License version 2. */ #include <libcflat.h> -#include <asm/interrupt.h> #include <asm/barrier.h> #include <sclp.h> +#include <interrupt.h> static bool pgm_int_expected;static bool ext_int_expected;
@@ -144,12 +144,33 @@ void handle_mcck_int(void) stap(), lc->mcck_old_psw.addr); } +static void (*io_int_func)(void ); +void handle_io_int (void ) { +if (io_int_func) +return io_int_func (); +report_abort ("Unexpected io interrupt: on cpu %d at %#lx" ,stap (), lc->io_old_psw.addr); } +int register_io_int_func (void (*f)(void )) +{ +if (io_int_func) +return -1 ; + io_int_func = f; +return 0 ; +} + +int unregister_io_int_func (void (*f)(void )) +{ +if (io_int_func != f) +return -1 ; + io_int_func =NULL ; +return 0 ; +} +void handle_svc_int (void ) { report_abort("Unexpected supervisor call interrupt: on cpu %d at %#lx",
lib/s390x/interrupt.h new file +8 -0
@@ -0,0 +1,8 @@ +#ifndef INTERRUPT_H +#define INTERRUPT_H +#include <asm/interrupt.h> + +int register_io_int_func (void (*f)(void )); +int unregister_io_int_func (void (*f)(void )); + +#endif /* INTERRUPT_H */
Signature · 1 line
2.25.4
[kvm-unit-tests GIT PULL 04/11] s390x: export the clock get_clock_ms() utility
In reply to Janosch FrankFrom: Pierre Morel <[email protected]>
To serve multiple times, the function get_clock_ms() is moved from intercept.c test to the new file asm/time.h.
Message-Id: <[email protected]>
--- lib/s390x/asm/time.h | 26 ++++++++++++++++++++++++++ s390x/intercept.c | 11 +---------- 2 files changed, 27 insertions(+), 10 deletions(-) create mode 100644 lib/s390x/asm/time.h
lib/s390x/asm/time.h new file +26 -0
@@ -0,0 +1,26 @@ +/* +* Clock utilities for s390 +* +* Authors: +* Thomas Huth <[email protected]> +* +* Copied from the s390/intercept test by: +* Pierre Morel <[email protected]> +* +* This code is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License version 2. +*/ +#ifndef ASM_S390X_TIME_H +#define ASM_S390X_TIME_H + +static inline uint64_t get_clock_ms (void ) +{ +uint64_t clk; + + asmvolatile (" stck %0 " : :"Q" (clk) :"memory" ); + +/* Bit 51 is incrememented each microsecond */ +return (clk >> (63 -51 )) /1000 ; +} + +#endif
s390x/intercept.c +1 -10
@@ -14,6 +14,7 @@#include <asm/interrupt.h> #include <asm/page.h> #include <asm/facility.h> +#include <asm/time.h> static uint8_t pagebuf[PAGE_SIZE * 2] __attribute__((aligned(PAGE_SIZE * 2)));
@@ -153,16 +154,6 @@ static void test_testblock(void)check_pgm_int_code (PGM_INT_CODE_ADDRESSING ); } -static uint64_t get_clock_ms (void ) -{ -uint64_t clk; - - asmvolatile (" stck %0 " : :"Q" (clk) :"memory" ); - -/* Bit 51 is incrememented each microsecond */ -return (clk >> (63 -51 )) /1000 ; -} -struct {const char *name;void (*func)(void );
Signature · 1 line
2.25.4
[kvm-unit-tests GIT PULL 05/11] s390x: clock and delays calculations
In reply to Janosch FrankFrom: Pierre Morel <[email protected]>
The hardware gives us a good definition of the microsecond, let's keep this information and let the routine accessing the hardware keep all the information and return microseconds.
Calculate delays in microseconds and take care about wrapping around zero.
Define values with macros and use inlines to keep the milliseconds interface.
Message-Id: <[email protected]>
--- lib/s390x/asm/time.h | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-)
lib/s390x/asm/time.h +27 -3
@@ -13,14 +13,38 @@#ifndef ASM_S390X_TIME_H #define ASM_S390X_TIME_H -static inline uint64_t get_clock_ms (void ) +#define STCK_SHIFT_US (63 - 51) +#define STCK_MAX ((1UL << 52) - 1) + +static inline uint64_t get_clock_us (void ) {uint64_t clk; asmvolatile (" stck %0 " : :"Q" (clk) :"memory" ); -/* Bit 51 is incrememented each microsecond */ -return (clk >> (63 -51 )) /1000 ; +return clk >>STCK_SHIFT_US ; +} + +static inline uint64_t get_clock_ms (void ) +{ +return get_clock_us () /1000 ; +} + +static inline void udelay (unsigned long us) +{ +unsigned long startclk =get_clock_us (); +unsigned long c; + +do { + c =get_clock_us (); +if (c < startclk) + c +=STCK_MAX ; + }while (c < startclk + us); +} + +static inline void mdelay (unsigned long ms) +{ +udelay (ms *1000 ); }#endif
Signature · 1 line
2.25.4
[kvm-unit-tests GIT PULL 06/11] s390x: define function to wait for interrupt
In reply to Janosch FrankFrom: Pierre Morel <[email protected]>
Allow the program to wait for an interrupt.
The interrupt handler is in charge to remove the WAIT bit when it finished handling the interrupt.
Message-Id: <[email protected]>
--- lib/s390x/asm/arch_def.h | 13 +++++++++++++ 1 file changed, 13 insertions(+)
lib/s390x/asm/arch_def.h +13 -0
@@ -17,6 +17,7 @@ struct psw {#define PSW_MASK_EXT 0x0100000000000000UL#define PSW_MASK_DAT 0x0400000000000000UL +#define PSW_MASK_WAIT 0x0002000000000000UL#define PSW_MASK_PSTATE 0x0001000000000000UL#define CR0_EXTM_SCLP 0x0000000000000200UL
@@ -246,6 +247,18 @@ static inline void load_psw_mask(uint64_t mask) : "+r" (tmp) : "a" (&psw) : "memory", "cc" ); } +static inline void wait_for_interrupt (uint64_t irq_mask) +{ +uint64_t psw_mask =extract_psw_mask (); + +load_psw_mask (psw_mask | irq_mask |PSW_MASK_WAIT ); +/* +* After being woken and having processed the interrupt, let's restore +* the PSW mask. +*/ +load_psw_mask (psw_mask); +} +static inline void enter_pstate (void ) {uint64_t mask;
Signature · 1 line
2.25.4
[kvm-unit-tests GIT PULL 07/11] s390x: Library resources for CSS tests
In reply to Janosch FrankFrom: Pierre Morel <[email protected]>
Provide some definitions and library routines that can be used by tests targeting the channel subsystem.
Message-Id: <[email protected]>
--- lib/s390x/css.h | 256 +++++++++++++++++++++++++++++++++++++++++++ lib/s390x/css_dump.c | 152 +++++++++++++++++++++++++ s390x/Makefile | 1 + 3 files changed, 409 insertions(+) create mode 100644 lib/s390x/css.h create mode 100644 lib/s390x/css_dump.c
lib/s390x/css.h new file +256 -0
@@ -0,0 +1,256 @@ +/* +* CSS definitions +* +* Copyright IBM, Corp. 2020 +* Author: Pierre Morel <[email protected]> +* +* This code is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License version 2. +*/ + +#ifndef CSS_H +#define CSS_H + +/* subchannel ID bit 16 must always be one */ +#define SCHID_ONE 0x00010000 + +#define CCW_F_CD 0x80 +#define CCW_F_CC 0x40 +#define CCW_F_SLI 0x20 +#define CCW_F_SKP 0x10 +#define CCW_F_PCI 0x08 +#define CCW_F_IDA 0x04 +#define CCW_F_S 0x02 +#define CCW_F_MIDA 0x01 + +#define CCW_C_NOP 0x03 +#define CCW_C_TIC 0x08 + +struct ccw1 { +uint8_t code; +uint8_t flags; +uint16_t count; +uint32_t data_address; +} __attribute__ ((aligned (8 ))); + +#define ORB_CTRL_KEY 0xf0000000 +#define ORB_CTRL_SPND 0x08000000 +#define ORB_CTRL_STR 0x04000000 +#define ORB_CTRL_MOD 0x02000000 +#define ORB_CTRL_SYNC 0x01000000 +#define ORB_CTRL_FMT 0x00800000 +#define ORB_CTRL_PFCH 0x00400000 +#define ORB_CTRL_ISIC 0x00200000 +#define ORB_CTRL_ALCC 0x00100000 +#define ORB_CTRL_SSIC 0x00080000 +#define ORB_CTRL_CPTC 0x00040000 +#define ORB_CTRL_C64 0x00020000 +#define ORB_CTRL_I2K 0x00010000 +#define ORB_CTRL_LPM 0x0000ff00 +#define ORB_CTRL_ILS 0x00000080 +#define ORB_CTRL_MIDAW 0x00000040 +#define ORB_CTRL_ORBX 0x00000001 + +#define ORB_LPM_DFLT 0x00008000 + +struct orb { +uint32_t intparm; +uint32_t ctrl; +uint32_t cpa; +uint32_t prio; +uint32_t reserved[4 ]; +} __attribute__ ((aligned (4 ))); + +struct scsw { +uint32_t ctrl; +uint32_t ccw_addr; +uint8_t dev_stat; +uint8_t sch_stat; +uint16_t count; +}; + +struct pmcw { +uint32_t intparm; +#define PMCW_DNV 0x0001 +#define PMCW_ENABLE 0x0080 +uint16_t flags; +uint16_t devnum; +uint8_t lpm; +uint8_t pnom; +uint8_t lpum; +uint8_t pim; +uint16_t mbi; +uint8_t pom; +uint8_t pam; +uint8_t chpid[8 ]; +uint32_t flags2; +}; +#define PMCW_CHANNEL_TYPE (pmcw) (pmcw->flags2 >> 21) + +struct schib { +struct pmcw pmcw; +struct scsw scsw; +uint8_t md[12 ]; +} __attribute__ ((aligned (4 ))); + +struct irb { +struct scsw scsw; +uint32_t esw[5 ]; +uint32_t ecw[8 ]; +uint32_t emw[8 ]; +} __attribute__ ((aligned (4 ))); + +/* CSS low level access functions */ + +static inline int ssch (unsigned long schid,struct orb *addr) +{ + register long long reg1 asm("1") = schid; +int cc; + + asmvolatile ( +" ssch 0(%2)\n" +" ipm %0\n" +" srl %0,28\n" + :"=d" (cc) + :"d" (reg1),"a" (addr),"m" (*addr) + :"cc" ,"memory" ); +return cc; +} + +static inline int stsch (unsigned long schid,struct schib *addr) +{ + register unsigned long reg1 asm ("1") = schid; +int cc; + + asmvolatile ( +" stsch 0(%3)\n" +" ipm %0\n" +" srl %0,28" + :"=d" (cc),"=m" (*addr) + :"d" (reg1),"a" (addr) + :"cc" ); +return cc; +} + +static inline int msch (unsigned long schid,struct schib *addr) +{ + register unsigned long reg1 asm ("1") = schid; +int cc; + + asmvolatile ( +" msch 0(%3)\n" +" ipm %0\n" +" srl %0,28" + :"=d" (cc) + :"d" (reg1),"m" (*addr),"a" (addr) + :"cc" ); +return cc; +} + +static inline int tsch (unsigned long schid,struct irb *addr) +{ + register unsigned long reg1 asm ("1") = schid; +int cc; + + asmvolatile ( +" tsch 0(%3)\n" +" ipm %0\n" +" srl %0,28" + :"=d" (cc),"=m" (*addr) + :"d" (reg1),"a" (addr) + :"cc" ); +return cc; +} + +static inline int hsch (unsigned long schid) +{ + register unsigned long reg1 asm("1") = schid; +int cc; + + asmvolatile ( +" hsch\n" +" ipm %0\n" +" srl %0,28" + :"=d" (cc) + :"d" (reg1) + :"cc" ); +return cc; +} + +static inline int xsch (unsigned long schid) +{ + register unsigned long reg1 asm("1") = schid; +int cc; + + asmvolatile ( +" xsch\n" +" ipm %0\n" +" srl %0,28" + :"=d" (cc) + :"d" (reg1) + :"cc" ); +return cc; +} + +static inline int csch (unsigned long schid) +{ + register unsigned long reg1 asm("1") = schid; +int cc; + + asmvolatile ( +" csch\n" +" ipm %0\n" +" srl %0,28" + :"=d" (cc) + :"d" (reg1) + :"cc" ); +return cc; +} + +static inline int rsch (unsigned long schid) +{ + register unsigned long reg1 asm("1") = schid; +int cc; + + asmvolatile ( +" rsch\n" +" ipm %0\n" +" srl %0,28" + :"=d" (cc) + :"d" (reg1) + :"cc" ); +return cc; +} + +static inline int rchp (unsigned long chpid) +{ + register unsigned long reg1 asm("1") = chpid; +int cc; + + asmvolatile ( +" rchp\n" +" ipm %0\n" +" srl %0,28" + :"=d" (cc) + :"d" (reg1) + :"cc" ); +return cc; +} + +/* Debug functions */ +char *dump_pmcw_flags (uint16_t f); +char *dump_scsw_flags (uint32_t f); + +void dump_scsw (struct scsw *scsw); +void dump_irb (struct irb *irbp); +void dump_schib (struct schib *sch); +struct ccw1 *dump_ccw (struct ccw1 *cp); +void dump_irb (struct irb *irbp); +void dump_pmcw (struct pmcw *p); +void dump_orb (struct orb *op); + +int css_enumerate (void ); +#define MAX_ENABLE_RETRIES 5 +int css_enable (int schid); + +#endif
lib/s390x/css_dump.c new file +152 -0
152 lines not on this page · raw message
s390x/Makefile +1 -0
@@ -52,6 +52,7 @@ cflatobjs += lib/s390x/interrupt.o cflatobjs += lib/s390x/mmu.o cflatobjs += lib/s390x/smp.o cflatobjs += lib/s390x/vm.o +cflatobjs += lib/s390x/css_dump.o OBJDIRS += lib/s390x
Signature · 1 line
2.25.4
[kvm-unit-tests GIT PULL 08/11] s390x: css: stsch, enumeration test
In reply to Janosch FrankFrom: Pierre Morel <[email protected]>
First step for testing the channel subsystem is to enumerate the css and retrieve the css devices.
We currently don't enable multiple subchannel sets and therefore only look in subchannel set 0
This tests the success of STSCH I/O instruction, we do not test the reaction of the VM for an instruction with wrong parameters.
Message-Id: <[email protected]>
--- lib/s390x/css_lib.c | 70 +++++++++++++++++++++++++++++++++++++++++++++ s390x/Makefile | 2 ++ s390x/css.c | 55 +++++++++++++++++++++++++++++++++++ s390x/unittests.cfg | 4 +++ 4 files changed, 131 insertions(+) create mode 100644 lib/s390x/css_lib.c create mode 100644 s390x/css.c
lib/s390x/css_lib.c new file +70 -0
@@ -0,0 +1,70 @@ +/* +* Channel Subsystem tests library +* +* Copyright (c) 2020 IBM Corp +* +* Authors: +* Pierre Morel <[email protected]> +* +* This code is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License version 2. +*/ +#include <libcflat.h> +#include <alloc_phys.h> +#include <asm/page.h> +#include <string.h> +#include <interrupt.h> +#include <asm/arch_def.h> + +#include <css.h> + +static struct schib schib; + +/* +* css_enumerate: +* On success return the first subchannel ID found. +* On error return an invalid subchannel ID containing cc +*/ +int css_enumerate (void ) +{ +struct pmcw *pmcw = &schib.pmcw; +int scn_found =0 ; +int dev_found =0 ; +int schid =0 ; +int cc; +int scn; + +for (scn =0 ; scn <0xffff ; scn++) { + cc =stsch (scn |SCHID_ONE , &schib); +switch (cc) { +case 0 :/* 0 means SCHIB stored */ +break ; +case 3 :/* 3 means no more channels */ + goto out; +default :/* 1 or 2 should never happen for STSCH */ +report_abort ("Unexpected error %d on subchannel %08x" , + cc, scn |SCHID_ONE ); +return cc; + } + +/* We currently only support type 0, a.k.a. I/O channels */ +if (PMCW_CHANNEL_TYPE (pmcw) !=0 ) +continue ; + +/* We ignore I/O channels without valid devices */ + scn_found++; +if (!(pmcw->flags &PMCW_DNV )) +continue ; + +/* We keep track of the first device as our test device */ +if (!schid) + schid = scn |SCHID_ONE ; +report_info ("Found subchannel %08x" , scn |SCHID_ONE ); + dev_found++; + } + +out: +report_info ("Tested subchannels: %d, I/O subchannels: %d, I/O devices: %d" , + scn, scn_found, dev_found); +return schid; +}
s390x/Makefile +2 -0
@@ -17,6 +17,7 @@ tests += $(TEST_DIR)/stsi.elf tests += $(TEST_DIR)/skrf.elf tests += $(TEST_DIR)/smp.elf tests += $(TEST_DIR)/sclp.elf +tests += $(TEST_DIR)/css.elf tests_binary = $(patsubst %.elf,%.bin,$(tests)) all: directories test_cases test_cases_binary
@@ -53,6 +54,7 @@ cflatobjs += lib/s390x/mmu.o cflatobjs += lib/s390x/smp.o cflatobjs += lib/s390x/vm.o cflatobjs += lib/s390x/css_dump.o +cflatobjs += lib/s390x/css_lib.o OBJDIRS += lib/s390x
s390x/css.c new file +55 -0
55 lines not on this page · raw message
s390x/unittests.cfg +4 -0
@@ -84,3 +84,7 @@ extra_params = -m 1G [sclp-3g] file = sclp.elf extra_params = -m 3G + +[css] +file = css.elf +extra_params = -device virtio-net-ccw
Signature · 1 line
2.25.4
[kvm-unit-tests GIT PULL 09/11] s390x: css: msch, enable test
In reply to Janosch FrankFrom: Pierre Morel <[email protected]>
A second step when testing the channel subsystem is to prepare a channel for use.
This includes:
- Get the current subchannel Information Block (SCHIB) using STSCH
- Update it in memory to set the ENABLE bit and the specified ISC
- Tell the CSS that the SCHIB has been modified using MSCH
- Get the SCHIB from the CSS again to verify that the subchannel is enabled and uses the specified ISC.
- If the command succeeds but subchannel is not enabled or the ISC field is not as expected, retry a predefined retries count.
- If the command fails, report the failure and do not retry, even if cc indicates a busy/status pending as we do not expect this.
This tests the MSCH instruction to enable a channel successfully. Retries are done and in case of error, and if the retries count is exceeded, a report is made.
Message-Id: <[email protected]>
--- lib/s390x/css.h | 9 ++++-- lib/s390x/css_lib.c | 73 +++++++++++++++++++++++++++++++++++++++++++++ s390x/css.c | 15 ++++++++++ 3 files changed, 94 insertions(+), 3 deletions(-)
lib/s390x/css.h +6 -3
@@ -71,8 +71,10 @@ struct scsw {struct pmcw {uint32_t intparm; -#define PMCW_DNV 0x0001 -#define PMCW_ENABLE 0x0080 +#define PMCW_DNV 0x0001 +#define PMCW_ENABLE 0x0080 +#define PMCW_ISC_MASK 0x3800 +#define PMCW_ISC_SHIFT 11uint16_t flags;uint16_t devnum;uint8_t lpm;
@@ -251,6 +253,7 @@ void dump_orb(struct orb *op);int css_enumerate (void );#define MAX_ENABLE_RETRIES 5 -int css_enable (int schid); +#define IO_SCH_ISC 3 +int css_enable (int schid,int isc);#endif
lib/s390x/css_lib.c +73 -0
82 lines not on this page · raw message
s390x/css.c +15 -0
@@ -31,11 +31,26 @@ static void test_enumerate(void)report (0 ,"No I/O device found" ); } +static void test_enable (void ) +{ +int cc; + +if (!test_device_sid) { +report_skip ("No device" ); +return ; + } + + cc =css_enable (test_device_sid,IO_SCH_ISC ); + +report (cc ==0 ,"Enable subchannel %08x" , test_device_sid); +} +static struct {const char *name;void (*func)(void ); } tests[] = { {"enumerate (stsch)" , test_enumerate }, + {"enable (msch)" , test_enable }, {NULL ,NULL } };
Signature · 1 line
2.25.4
[kvm-unit-tests GIT PULL 10/11] s390x: css: ssch/tsch with sense and interrupt
In reply to Janosch FrankFrom: Pierre Morel <[email protected]>
After a channel is enabled we start a SENSE_ID command using the SSCH instruction to recognize the control unit and device.
This tests the success of SSCH, the I/O interruption and the TSCH instructions.
The SENSE_ID command response is tested to report 0xff inside its reserved field and to report the same control unit type as the cu_type kernel argument.
Without the cu_type kernel argument, the test expects a device with a default control unit type of 0x3832, a.k.a virtio-net-ccw.
Message-Id: <[email protected]>
--- lib/s390x/asm/arch_def.h | 1 + lib/s390x/css.h | 35 ++++++++ lib/s390x/css_lib.c | 177 +++++++++++++++++++++++++++++++++++++++ s390x/css.c | 80 ++++++++++++++++++ 4 files changed, 293 insertions(+)
lib/s390x/asm/arch_def.h +1 -0
@@ -16,6 +16,7 @@ struct psw { };#define PSW_MASK_EXT 0x0100000000000000UL +#define PSW_MASK_IO 0x0200000000000000UL#define PSW_MASK_DAT 0x0400000000000000UL#define PSW_MASK_WAIT 0x0002000000000000UL#define PSW_MASK_PSTATE 0x0001000000000000UL
lib/s390x/css.h +35 -0
@@ -11,6 +11,8 @@#ifndef CSS_H #define CSS_H +#define lowcore_ptr ((struct lowcore *)0x0) +/* subchannel ID bit 16 must always be one */ #define SCHID_ONE 0x00010000
@@ -62,9 +64,18 @@ struct orb { } __attribute__ ((aligned(4)));struct scsw { +#define SCSW_SC_PENDING 0x00000001 +#define SCSW_SC_SECONDARY 0x00000002 +#define SCSW_SC_PRIMARY 0x00000004 +#define SCSW_SC_INTERMEDIATE 0x00000008 +#define SCSW_SC_ALERT 0x00000010uint32_t ctrl;uint32_t ccw_addr; +#define SCSW_DEVS_DEV_END 0x04 +#define SCSW_DEVS_SCH_END 0x08uint8_t dev_stat; +#define SCSW_SCHS_PCI 0x80 +#define SCSW_SCHS_IL 0x40uint8_t sch_stat;uint16_t count; };
@@ -102,6 +113,19 @@ struct irb {uint32_t emw[8 ]; } __attribute__ ((aligned(4))); +#define CCW_CMD_SENSE_ID 0xe4 +#define CSS_SENSEID_COMMON_LEN 8 +struct senseid { +/* common part */ +uint8_t reserved;/* always 0x'FF' */ +uint16_t cu_type;/* control unit type */ +uint8_t cu_model;/* control unit model */ +uint16_t dev_type;/* device type */ +uint8_t dev_model;/* device model */ +uint8_t unused;/* padding byte */ +uint8_t padding[256 -8 ];/* Extended part */ +} __attribute__ ((aligned(4))) __attribute__ ((packed)); +/* CSS low level access functions */ static inline int ssch (unsigned long schid,struct orb *addr)
@@ -256,4 +280,15 @@ int css_enumerate(void);#define IO_SCH_ISC 3int css_enable (int schid,int isc); + +/* Library functions */ +int start_ccw1_chain (unsigned int sid,struct ccw1 *ccw); +int start_single_ccw (unsigned int sid,int code,void *data,int count, +unsigned char flags); +void css_irq_io (void ); +int css_residual_count (unsigned int schid); + +void enable_io_isc (uint8_t isc); +int wait_and_check_io_completion (int schid); +#endif
lib/s390x/css_lib.c +177 -0
186 lines not on this page · raw message
s390x/css.c +80 -0
105 lines not on this page · raw message
Signature · 1 line
2.25.4
[kvm-unit-tests GIT PULL 11/11] s390x: fix inline asm on gcc10
In reply to Janosch FrankFrom: Claudio Imbrenda <[email protected]>
Fix compilation issues on 390x with gcc 10.
Simply mark the inline functions that lead to a .insn with a variable opcode as __always_inline, to make gcc 10 happy.
Message-Id: <[email protected]>
--- lib/s390x/asm/cpacf.h | 5 +++-- s390x/emulator.c | 25 +++++++++++++------------ 2 files changed, 16 insertions(+), 14 deletions(-)
lib/s390x/asm/cpacf.h +3 -2
@@ -11,6 +11,7 @@#define _ASM_S390_CPACF_H#include <asm/facility.h> +#include <linux/compiler.h> /* * Instruction opcodes for the CPACF instructions
@@ -145,7 +146,7 @@ typedef struct { unsigned char bytes[16]; } cpacf_mask_t;* * Returns 1 if @func is available for @opcode, 0 otherwise */ -static inline void __cpacf_query (unsigned int opcode,cpacf_mask_t *mask) +static __always_inline void __cpacf_query(unsigned int opcode, cpacf_mask_t *mask) { register unsigned long r0 asm("0") = 0; /* query function */ register unsigned long r1 asm("1") = (unsigned long) mask;
@@ -183,7 +184,7 @@ static inline int __cpacf_check_opcode(unsigned int opcode) } } -static inline int cpacf_query (unsigned int opcode,cpacf_mask_t *mask) +static __always_inline int cpacf_query(unsigned int opcode, cpacf_mask_t *mask) {if (__cpacf_check_opcode (opcode)) {__cpacf_query (opcode, mask);
s390x/emulator.c +13 -12
@@ -14,6 +14,7 @@#include <asm/cpacf.h> #include <asm/interrupt.h> #include <asm/float.h> +#include <linux/compiler.h> struct lowcore *lc =NULL ;
@@ -46,7 +47,7 @@ static void test_spm_ipm(void)__test_spm_ipm (0 ,0 ); } -static inline void __test_cpacf (unsigned int opcode,unsigned long func, +static __always_inline void __test_cpacf(unsigned int opcode, unsigned long func,unsigned int r1,unsigned int r2,unsigned int r3) {
@@ -59,7 +60,7 @@ static inline void __test_cpacf(unsigned int opcode, unsigned long func, [r1] "i" (r1), [r2] "i" (r2), [r3] "i" (r3)); } -static inline void __test_cpacf_r1_odd(unsigned int opcode) +static __always_inline void __test_cpacf_r1_odd(unsigned int opcode) {report_prefix_push ("r1 odd" );expect_pgm_int ();
@@ -68,7 +69,7 @@ static inline void __test_cpacf_r1_odd(unsigned int opcode)report_prefix_pop (); } -static inline void __test_cpacf_r1_null (unsigned int opcode) +static __always_inline void __test_cpacf_r1_null(unsigned int opcode) {report_prefix_push ("r1 null" );expect_pgm_int ();
@@ -77,7 +78,7 @@ static inline void __test_cpacf_r1_null(unsigned int opcode)report_prefix_pop (); } -static inline void __test_cpacf_r2_odd (unsigned int opcode) +static __always_inline void __test_cpacf_r2_odd(unsigned int opcode) {report_prefix_push ("r2 odd" );expect_pgm_int ();
@@ -86,7 +87,7 @@ static inline void __test_cpacf_r2_odd(unsigned int opcode)report_prefix_pop (); } -static inline void __test_cpacf_r2_null (unsigned int opcode) +static __always_inline void __test_cpacf_r2_null(unsigned int opcode) {report_prefix_push ("r2 null" );expect_pgm_int ();
@@ -95,7 +96,7 @@ static inline void __test_cpacf_r2_null(unsigned int opcode)report_prefix_pop (); } -static inline void __test_cpacf_r3_odd (unsigned int opcode) +static __always_inline void __test_cpacf_r3_odd(unsigned int opcode) {report_prefix_push ("r3 odd" );expect_pgm_int ();
@@ -104,7 +105,7 @@ static inline void __test_cpacf_r3_odd(unsigned int opcode)report_prefix_pop (); } -static inline void __test_cpacf_r3_null (unsigned int opcode) +static __always_inline void __test_cpacf_r3_null(unsigned int opcode) {report_prefix_push ("r3 null" );expect_pgm_int ();
@@ -113,7 +114,7 @@ static inline void __test_cpacf_r3_null(unsigned int opcode)report_prefix_pop (); } -static inline void __test_cpacf_mod_bit (unsigned int opcode) +static __always_inline void __test_cpacf_mod_bit(unsigned int opcode) {report_prefix_push ("mod bit" );expect_pgm_int ();
@@ -122,7 +123,7 @@ static inline void __test_cpacf_mod_bit(unsigned int opcode)report_prefix_pop (); } -static inline void __test_cpacf_invalid_func (unsigned int opcode) +static __always_inline void __test_cpacf_invalid_func(unsigned int opcode) {report_prefix_push ("invalid subfunction" );expect_pgm_int ();
@@ -137,7 +138,7 @@ static inline void __test_cpacf_invalid_func(unsigned int opcode)report_prefix_pop (); } -static inline void __test_cpacf_invalid_parm (unsigned int opcode) +static __always_inline void __test_cpacf_invalid_parm(unsigned int opcode) {report_prefix_push ("invalid parm address" );expect_pgm_int ();
@@ -146,7 +147,7 @@ static inline void __test_cpacf_invalid_parm(unsigned int opcode)report_prefix_pop (); } -static inline void __test_cpacf_protected_parm (unsigned int opcode) +static __always_inline void __test_cpacf_protected_parm(unsigned int opcode) {report_prefix_push ("protected parm address" );expect_pgm_int ();
@@ -157,7 +158,7 @@ static inline void __test_cpacf_protected_parm(unsigned int opcode)report_prefix_pop (); } -static inline void __test_basic_cpacf_opcode (unsigned int opcode) +static __always_inline void __test_basic_cpacf_opcode(unsigned int opcode) {bool mod_bit_allowed = false;
Signature · 1 line
2.25.4
Paolo Bonzini
maintainerQuoted 1 line · Janosch Frank
https://github.com/frankjaa/kvm-unit-tests.git tags/s390x-2020-31-07
Pulled, thanks. FWIW you may want to gitlab in order to get the CI.
Paolo
Quoted 7 lines · Paolo Bonzini
Quoted 1 line · Janosch Frank
https://github.com/frankjaa/kvm-unit-tests.git tags/s390x-2020-31-07
Pulled, thanks. FWIW you may want to gitlab in order to get the CI.
Paolo
Hey Paolo, that repository is hooked up to travis already:
https://travis-ci.com/github/frankjaa/kvm-unit-tests/builds/177931162
I'll consider it if it has any benefit.
@Thomas: Are there differences in the CI?
Quoted 6 lines · Janosch Frank
Quoted 5 lines · Paolo Bonzini
Quoted 1 line · Janosch Frank
https://github.com/frankjaa/kvm-unit-tests.git tags/s390x-2020-31-07
Pulled, thanks. FWIW you may want to gitlab in order to get the CI.
Quoted 8 lines
Quoted 2 lines
Paolo
Hey Paolo, that repository is hooked up to travis already:
https://travis-ci.com/github/frankjaa/kvm-unit-tests/builds/177931162I'll consider it if it has any benefit.
@Thomas: Are there differences in the CI?
Not that much, you get a good build test coverage with both. Travis uses real (nested) KVM tests, but the compiler and QEMU versions are a little bit backlevel (still using Ubuntu bionic). Gitlab-CI uses newer versions (thanks to Fedora 32), but there is no KVM support here, so the tests run with TCG only (I'm thinking of adding the cirrus-run script to the Gitlab-CI, maybe we could get some KVM-coverage that way there, too, but that will certainly take some time to figure it out).
Thomas
Quoted 24 lines · Thomas Huth
Quoted 6 lines · Janosch Frank
Quoted 5 lines · Paolo Bonzini
Quoted 1 line · Janosch Frank
https://github.com/frankjaa/kvm-unit-tests.git tags/s390x-2020-31-07
Pulled, thanks. FWIW you may want to gitlab in order to get the CI.
Quoted 8 lines
Quoted 2 lines
Paolo
Hey Paolo, that repository is hooked up to travis already:
https://travis-ci.com/github/frankjaa/kvm-unit-tests/builds/177931162I'll consider it if it has any benefit.
@Thomas: Are there differences in the CI?Not that much, you get a good build test coverage with both. Travis uses real (nested) KVM tests, but the compiler and QEMU versions are a little bit backlevel (still using Ubuntu bionic). Gitlab-CI uses newer versions (thanks to Fedora 32), but there is no KVM support here, so the tests run with TCG only (I'm thinking of adding the cirrus-run script to the Gitlab-CI, maybe we could get some KVM-coverage that way there, too, but that will certainly take some time to figure it out).
Quoted 2 lines
Thomas
Thanks for the answer!
For now I'll stay with github/travis until I have a real reason to move over. Maybe if the qemu CI run doesn't take ~2h on gitlab I'll start considering moving.