s390x: Add SIE library and simple test
cover s390x: Add SIE library and simple test
This is the absolute minimum needed to run VMs inside the KVM Unit Tests. It's more of a base for other tests that I can't (yet) publish than an addition of tests that check KVM functionality. However, I wanted to decrease the number of WIP patches in my private branch. Once the library is available maybe others will come and extend the SIE test itself.
Yes, I have added VM management functionality like VM create/destroy, etc but as it is not needed right now, I'd like to exclude it from this patch set for now.
Gitlab:
https://gitlab.com/frankja/kvm-unit-tests/-/tree/sie
CI:
https://gitlab.com/frankja/kvm-unit-tests/-/pipelines/217336822
Janosch Frank (5):
s390x: Add test_bit to library
s390x: Consolidate sclp read info
s390x: SCLP feature checking
s390x: sie: Add SIE to lib
s390x: sie: Add first SIE test
lib/s390x/asm-offsets.c | 13 +++ lib/s390x/asm/arch_def.h | 7 ++ lib/s390x/asm/bitops.h | 16 ++++ lib/s390x/asm/facility.h | 3 +- lib/s390x/interrupt.c | 7 ++ lib/s390x/io.c | 2 + lib/s390x/sclp.c | 48 ++++++++-- lib/s390x/sclp.h | 18 ++++ lib/s390x/sie.h | 197 +++++++++++++++++++++++++++++++++++++++ lib/s390x/smp.c | 23 ++--- s390x/Makefile | 1 + s390x/cstart64.S | 56 +++++++++++ s390x/sie.c | 125 +++++++++++++++++++++++++ 13 files changed, 495 insertions(+), 21 deletions(-) create mode 100644 lib/s390x/sie.h create mode 100644 s390x/sie.c
Signature · 1 line
2.25.1
PATCH 1/5 s390x: Add test_bit to library
Query/feature bits are commonly tested via MSB bit numbers on s390. Let's add test bit functions, so we don't need to copy code to test query bits.
--- lib/s390x/asm/bitops.h | 16 ++++++++++++++++ lib/s390x/asm/facility.h | 3 ++- 2 files changed, 18 insertions(+), 1 deletion(-)
lib/s390x/asm/bitops.h +16 -0
@@ -7,4 +7,20 @@#define BITS_PER_LONG 64 +static inline bool test_bit (unsigned long nr, +const volatile unsigned long *ptr) +{ +const volatile unsigned char *addr; + + addr = ((const volatile unsigned char *)ptr); + addr += (nr ^ (BITS_PER_LONG -8 )) >>3 ; +return (*addr >> (nr &7 )) &1 ; +} + +static inline bool test_bit_inv (unsigned long nr, +const volatile unsigned long *ptr) +{ +return test_bit (nr ^ (BITS_PER_LONG -1 ), ptr); +} +#endif
lib/s390x/asm/facility.h +2 -1
@@ -13,13 +13,14 @@#include <libcflat.h> #include <asm/facility.h> #include <asm/arch_def.h> +#include <bitops.h> #define NB_STFL_DOUBLEWORDS 32extern uint64_t stfl_doublewords[];static inline bool test_facility (int nr) { -return stfl_doublewords[nr /64 ] & (0x8000000000000000UL >> (nr %64 )); +return test_bit_inv (nr, stfl_doublewords); }static inline void stfl (void )
Signature · 1 line
2.25.1
Re: [kvm-unit-tests PATCH 1/5] s390x: Add test_bit to library
Quoted 9 lines · On Tue, 17 Nov 2020 10:42:11 -0500 Janosch Frank <[email protected]> wrote:
Query/feature bits are commonly tested via MSB bit numbers on s390. Let's add test bit functions, so we don't need to copy code to test query bits.
Signed-off-by Janosch Frank <[email protected]>--- lib/s390x/asm/bitops.h | 16 ++++++++++++++++ lib/s390x/asm/facility.h | 3 ++- 2 files changed, 18 insertions(+), 1 deletion(-)
Re: [kvm-unit-tests PATCH 1/5] s390x: Add test_bit to library
In reply to Janosch FrankQuoted 23 lines · Janosch Frank
Query/feature bits are commonly tested via MSB bit numbers on s390. Let's add test bit functions, so we don't need to copy code to test query bits.
Signed-off-by Janosch Frank <[email protected]>--- lib/s390x/asm/bitops.h | 16 ++++++++++++++++ lib/s390x/asm/facility.h | 3 ++- 2 files changed, 18 insertions(+), 1 deletion(-)lib/s390x/asm/bitops.h +5
-0@@ -7,4 +7,20 @@#define BITS_PER_LONG 64 +static inline bool test_bit (unsigned long nr, +const volatile unsigned long *ptr) +{ +const volatile unsigned char *addr; +
lib/s390x/asm/bitops.h line 24
Quoted 10 lines
lib/s390x/asm/bitops.h +10
-0+ addr = ((const volatile unsigned char *)ptr); + addr += (nr ^ (BITS_PER_LONG -8 )) >>3 ; +return (*addr >> (nr &7 )) &1 ; +} + +static inline bool test_bit_inv (unsigned long nr, +const volatile unsigned long *ptr) +{ +return test_bit (nr ^ (BITS_PER_LONG -1 ), ptr); +}
I think you should mention in the patch description that these functions match the implementations in the kernel (and thus are good for kernel developers who are used to these).
Thus I think you should also now add a license statement to this file ("SPDX-License-Identifier: GPL-2.0" or so).
With these modifications:
Re: [kvm-unit-tests PATCH 1/5] s390x: Add test_bit to library
Quoted 30 lines · Thomas Huth
Quoted 29 lines · Janosch Frank
Query/feature bits are commonly tested via MSB bit numbers on s390. Let's add test bit functions, so we don't need to copy code to test query bits.
Signed-off-by Janosch Frank <[email protected]>--- lib/s390x/asm/bitops.h | 16 ++++++++++++++++ lib/s390x/asm/facility.h | 3 ++- 2 files changed, 18 insertions(+), 1 deletion(-)lib/s390x/asm/bitops.h +11
-0@@ -7,4 +7,20 @@#define BITS_PER_LONG 64 +static inline bool test_bit (unsigned long nr, +const volatile unsigned long *ptr) +{ +const volatile unsigned char *addr; + + addr = ((const volatile unsigned char *)ptr); + addr += (nr ^ (BITS_PER_LONG -8 )) >>3 ; +return (*addr >> (nr &7 )) &1 ; +} + +static inline bool test_bit_inv(unsigned long nr,
Quoted 8 lines
lib/s390x/asm/bitops.h line 24
Quoted 4 lines
lib/s390x/asm/bitops.h +4
-0+ const volatile unsigned long *ptr) +{ +return test_bit (nr ^ (BITS_PER_LONG -1 ), ptr); +}I think you should mention in the patch description that these functions match the implementations in the kernel (and thus are good for kernel developers who are used to these).
There are only so many ways one can write 4 lines of code :-)
Quoted 3 lines
Thus I think you should also now add a license statement to this file ("SPDX-License-Identifier: GPL-2.0" or so).
Definitely, thanks for reminding me
Quoted 4 lines
With these modifications:
Reviewed-by Thomas Huth <[email protected]>
Thanks
PATCH 2/5 s390x: Consolidate sclp read info
In reply to Janosch FrankLet's only read the information once and pass a pointer to it instead of calling sclp multiple times.
--- lib/s390x/io.c | 1 + lib/s390x/sclp.c | 29 +++++++++++++++++++++++------ lib/s390x/sclp.h | 3 +++ lib/s390x/smp.c | 23 +++++++++-------------- 4 files changed, 36 insertions(+), 20 deletions(-)
lib/s390x/io.c +1 -0
@@ -36,6 +36,7 @@ void setup(void) {setup_args_progname (ipl_args);setup_facilities (); +sclp_read_info ();sclp_console_setup ();sclp_memory_setup ();smp_setup ();
lib/s390x/sclp.c +23 -6
@@ -25,6 +25,8 @@ extern unsigned long stacktop;static uint64_t storage_increment_size;static uint64_t max_ram_size;static uint64_t ram_size; +char _read_info[PAGE_SIZE] __attribute__((__aligned__(4096))); +static ReadInfo *read_info; char _sccb[PAGE_SIZE] __attribute__((__aligned__(4096)));static volatile bool sclp_busy;
@@ -110,6 +112,22 @@ static void sclp_read_scp_info(ReadInfo *ri, int length)report_abort ("READ_SCP_INFO failed" ); } +void sclp_read_info (void ) +{ +sclp_read_scp_info ((void *)_read_info,SCCB_SIZE ); + read_info = (ReadInfo *)_read_info; +} + +int sclp_get_cpu_num (void ) +{ +return read_info->entries_cpu; +} + +CPUEntry *sclp_get_cpu_entries (void ) +{ +return (void *)read_info + read_info->offset_cpu; +} +/* Perform service call. Return 0 on success, non-zero otherwise. */ int sclp_service_call (unsigned int command,void *sccb) {
@@ -127,23 +145,22 @@ int sclp_service_call(unsigned int command, void *sccb)void sclp_memory_setup (void ) { -ReadInfo *ri = (void *)_sccb;uint64_t rnmax, rnsize;int cc; -sclp_read_scp_info (ri,SCCB_SIZE ); +assert (read_info);/* calculate the storage increment size */ - rnsize = ri->rnsize; + rnsize = read_info->rnsize;if (!rnsize) { - rnsize = ri->rnsize2; + rnsize = read_info->rnsize2; } storage_increment_size = rnsize <<20 ;/* calculate the maximum memory size */ - rnmax = ri->rnmax; + rnmax = read_info->rnmax;if (!rnmax) { - rnmax = ri->rnmax2; + rnmax = read_info->rnmax2; } max_ram_size = rnmax * storage_increment_size;
lib/s390x/sclp.h +3 -0
@@ -271,6 +271,9 @@ void sclp_wait_busy(void);void sclp_mark_busy (void );void sclp_console_setup (void );void sclp_print (const char *str); +void sclp_read_info (void ); +int sclp_get_cpu_num (void ); +CPUEntry *sclp_get_cpu_entries (void );int sclp_service_call (unsigned int command,void *sccb);void sclp_memory_setup (void );uint64_t get_ram_size (void );
lib/s390x/smp.c +9 -14
@@ -34,8 +34,7 @@ extern void smp_cpu_setup_state(void);int smp_query_num_cpus (void ) { -struct ReadCpuInfo *info = (void *)cpu_info_buffer; -return info->nr_configured; +return sclp_get_cpu_num (); }struct cpu *smp_cpu_from_addr (uint16_t addr)
@@ -245,22 +244,18 @@ extern uint64_t *stackptr;void smp_setup (void ) {int i =0 ; +int num =smp_query_num_cpus ();unsigned short cpu0_addr =stap (); -struct ReadCpuInfo *info = (void *)cpu_info_buffer; +struct CPUEntry *entry =sclp_get_cpu_entries (); -spin_lock (&lock); -sclp_mark_busy (); - info->h.length =PAGE_SIZE ; -sclp_service_call (SCLP_READ_CPU_INFO , cpu_info_buffer); +if (num >1 ) +printf ("SMP: Initializing, found %d cpus\n" , num); -if (smp_query_num_cpus () >1 ) -printf ("SMP: Initializing, found %d cpus\n" , info->nr_configured); - - cpus =calloc (info->nr_configured,sizeof (cpus)); -for (i =0 ; i < info->nr_configured; i++) { - cpus[i].addr = info->entries[i].address; + cpus =calloc (num,sizeof (cpus)); +for (i =0 ; i < num; i++) { + cpus[i].addr = entry[i].address; cpus[i].active = false; -if (info->entries[i].address == cpu0_addr) { +if (entry[i].address == cpu0_addr) { cpu0 = &cpus[i]; cpu0->stack = stackptr; cpu0->lowcore = (void *)0 ;
Signature · 1 line
2.25.1
Re: [kvm-unit-tests PATCH 2/5] s390x: Consolidate sclp read info
Quoted 10 lines · On Tue, 17 Nov 2020 10:42:12 -0500 Janosch Frank <[email protected]> wrote:
Let's only read the information once and pass a pointer to it instead of calling sclp multiple times.
Signed-off-by Janosch Frank <[email protected]>--- lib/s390x/io.c | 1 + lib/s390x/sclp.c | 29 +++++++++++++++++++++++------ lib/s390x/sclp.h | 3 +++ lib/s390x/smp.c | 23 +++++++++-------------- 4 files changed, 36 insertions(+), 20 deletions(-)
Re: [kvm-unit-tests PATCH 2/5] s390x: Consolidate sclp read info
In reply to Janosch FrankQuoted 50 lines · Janosch Frank
Let's only read the information once and pass a pointer to it instead of calling sclp multiple times.
Signed-off-by Janosch Frank <[email protected]>--- lib/s390x/io.c | 1 + lib/s390x/sclp.c | 29 +++++++++++++++++++++++------ lib/s390x/sclp.h | 3 +++ lib/s390x/smp.c | 23 +++++++++-------------- 4 files changed, 36 insertions(+), 20 deletions(-)lib/s390x/io.c +1
-0@@ -36,6 +36,7 @@ void setup(void) {setup_args_progname (ipl_args);setup_facilities (); +sclp_read_info ();sclp_console_setup ();sclp_memory_setup ();smp_setup ();lib/s390x/sclp.c +12
-0@@ -25,6 +25,8 @@ extern unsigned long stacktop;static uint64_t storage_increment_size;static uint64_t max_ram_size;static uint64_t ram_size; +char _read_info[PAGE_SIZE] __attribute__((__aligned__(4096))); +static ReadInfo *read_info; char _sccb[PAGE_SIZE] __attribute__((__aligned__(4096)));static volatile bool sclp_busy;@@ -110,6 +112,22 @@ static void sclp_read_scp_info(ReadInfo *ri, int length)report_abort ("READ_SCP_INFO failed" ); } +void sclp_read_info (void ) +{ +sclp_read_scp_info ((void *)_read_info,SCCB_SIZE ); + read_info = (ReadInfo *)_read_info; +} + +int sclp_get_cpu_num (void ) +{ +return read_info->entries_cpu; +}
[...]
lib/s390x/sclp.c
Quoted 6 lines
int
smp_query_num_cpus(void)
{lib/s390x/sclp.c +1
-2-struct ReadCpuInfo *info = (void *)cpu_info_buffer; -return info->nr_configured; +return sclp_get_cpu_num (); }
You've changed from ->nr_configured to ->entries_cpu ... I assume that's ok? Worth to mention the change and rationale in the patch description?
Quoted 23 lines
struct cpu *smp_cpu_from_addr(uint16_t addr)
lib/s390x/sclp.c +4
-10@@ -245,22 +244,18 @@ extern uint64_t *stackptr;void smp_setup (void ) {int i =0 ; +int num =smp_query_num_cpus ();unsigned short cpu0_addr =stap (); -struct ReadCpuInfo *info = (void *)cpu_info_buffer; +struct CPUEntry *entry =sclp_get_cpu_entries (); -spin_lock (&lock); -sclp_mark_busy (); - info->h.length =PAGE_SIZE ; -sclp_service_call (SCLP_READ_CPU_INFO , cpu_info_buffer); +if (num >1 ) +printf ("SMP: Initializing, found %d cpus\n" , num); -if (smp_query_num_cpus () >1 ) -printf ("SMP: Initializing, found %d cpus\n" , info->nr_configured); - - cpus =calloc (info->nr_configured,sizeof (cpus)); -for (i =0 ; i < info->nr_configured; i++) {
lib/s390x/sclp.c extern uint64_t *stackptr; · line 261
Quoted 10 lines
lib/s390x/sclp.c +4
-2- cpus[i].addr = info->entries[i].address; + cpus =calloc (num,sizeof (cpus)); +for (i =0 ; i < num; i++) { + cpus[i].addr = entry[i].address; cpus[i].active = false; -if (info->entries[i].address == cpu0_addr) { +if (entry[i].address == cpu0_addr) { cpu0 = &cpus[i]; cpu0->stack = stackptr; cpu0->lowcore = (void *)0 ;
What about smp_teardown()? It seems to use cpu_info_buffer->nr_configured, too, which is now likely not valid anymore?
Thomas
Re: [kvm-unit-tests PATCH 2/5] s390x: Consolidate sclp read info
Quoted 52 lines · Thomas Huth
Quoted 50 lines · Janosch Frank
Let's only read the information once and pass a pointer to it instead of calling sclp multiple times.
Signed-off-by Janosch Frank <[email protected]>--- lib/s390x/io.c | 1 + lib/s390x/sclp.c | 29 +++++++++++++++++++++++------ lib/s390x/sclp.h | 3 +++ lib/s390x/smp.c | 23 +++++++++-------------- 4 files changed, 36 insertions(+), 20 deletions(-)lib/s390x/io.c +1
-0@@ -36,6 +36,7 @@ void setup(void) {setup_args_progname (ipl_args);setup_facilities (); +sclp_read_info ();sclp_console_setup ();sclp_memory_setup ();smp_setup ();lib/s390x/sclp.c +12
-0@@ -25,6 +25,8 @@ extern unsigned long stacktop;static uint64_t storage_increment_size;static uint64_t max_ram_size;static uint64_t ram_size; +char _read_info[PAGE_SIZE] __attribute__((__aligned__(4096))); +static ReadInfo *read_info; char _sccb[PAGE_SIZE] __attribute__((__aligned__(4096)));static volatile bool sclp_busy;@@ -110,6 +112,22 @@ static void sclp_read_scp_info(ReadInfo *ri, int length)report_abort ("READ_SCP_INFO failed" ); } +void sclp_read_info (void ) +{ +sclp_read_scp_info ((void *)_read_info,SCCB_SIZE ); + read_info = (ReadInfo *)_read_info; +} + +int sclp_get_cpu_num (void ) +{ +return read_info->entries_cpu; +}[...]
Quoted 9 lines
lib/s390x/sclp.c
Quoted 6 lines
int
smp_query_num_cpus(void)
{lib/s390x/sclp.c +1
-2-struct ReadCpuInfo *info = (void *)cpu_info_buffer; -return info->nr_configured; +return sclp_get_cpu_num (); }You've changed from ->nr_configured to ->entries_cpu ... I assume that's ok? Worth to mention the change and rationale in the patch description?
Well, it's not so much a change of struct members than a change of structs themselves. Looking at our QEMU implementation, both struct members transport the same data so I don't see a problem there.
Quoted 29 lines
Quoted 29 lines
struct cpu *smp_cpu_from_addr(uint16_t addr)
lib/s390x/sclp.c +7
-12@@ -245,22 +244,18 @@ extern uint64_t *stackptr;void smp_setup (void ) {int i =0 ; +int num =smp_query_num_cpus ();unsigned short cpu0_addr =stap (); -struct ReadCpuInfo *info = (void *)cpu_info_buffer; +struct CPUEntry *entry =sclp_get_cpu_entries (); -spin_lock (&lock); -sclp_mark_busy (); - info->h.length =PAGE_SIZE ; -sclp_service_call (SCLP_READ_CPU_INFO , cpu_info_buffer); +if (num >1 ) +printf ("SMP: Initializing, found %d cpus\n" , num); -if (smp_query_num_cpus () >1 ) -printf ("SMP: Initializing, found %d cpus\n" , info->nr_configured); - - cpus =calloc (info->nr_configured,sizeof (cpus)); -for (i =0 ; i < info->nr_configured; i++) { - cpus[i].addr = info->entries[i].address; + cpus =calloc (num,sizeof (cpus)); +for (i =0 ; i < num; i++) { + cpus[i].addr = entry[i].address; cpus[i].active = false; -if (info->entries[i].address == cpu0_addr) {
Quoted 8 lines
lib/s390x/sclp.c extern uint64_t *stackptr; · line 261
Quoted 5 lines
lib/s390x/sclp.c +1
-0+if (entry[i].address == cpu0_addr) { cpu0 = &cpus[i]; cpu0->stack = stackptr; cpu0->lowcore = (void *)0 ;What about
smp_teardown()? It seems to usecpu_info_buffer->nr_configured, too, which is now likely not valid anymore?
Good catch, I forgot to remove the whole cpu info buffer.
Quoted 3 lines
Thomas
PATCH 3/5 s390x: SCLP feature checking
In reply to Janosch FrankAvailability of SIE is announced via a feature bit in a SCLP info CPU entry. Let's add a framework that allows us to easily check for such facilities.
--- lib/s390x/io.c | 1 + lib/s390x/sclp.c | 19 +++++++++++++++++++ lib/s390x/sclp.h | 15 +++++++++++++++ 3 files changed, 35 insertions(+)
lib/s390x/io.c +1 -0
@@ -37,6 +37,7 @@ void setup(void)setup_args_progname (ipl_args);setup_facilities ();sclp_read_info (); +sclp_facilities_setup ();sclp_console_setup ();sclp_memory_setup ();smp_setup ();
lib/s390x/sclp.c +19 -0
@@ -11,6 +11,7 @@*/ #include <libcflat.h> +#include <bitops.h> #include <asm/page.h> #include <asm/arch_def.h> #include <asm/interrupt.h>
@@ -27,6 +28,7 @@ static uint64_t max_ram_size;static uint64_t ram_size; char _read_info[PAGE_SIZE] __attribute__((__aligned__(4096)));static ReadInfo *read_info; +struct sclp_facilities sclp_facilities; char _sccb[PAGE_SIZE] __attribute__((__aligned__(4096)));static volatile bool sclp_busy;
@@ -128,6 +130,23 @@ CPUEntry *sclp_get_cpu_entries(void)return (void *)read_info + read_info->offset_cpu; } +void sclp_facilities_setup (void ) +{ +unsigned short cpu0_addr =stap (); +CPUEntry *cpu; +int i; + +assert (read_info); + + cpu = (void *)read_info + read_info->offset_cpu; +for (i =0 ; i < read_info->entries_cpu; i++, cpu++) { +if (cpu->address == cpu0_addr) { + sclp_facilities.has_sief2 =test_bit_inv (SCLP_CPU_FEATURE_SIEF2_BIT , (void *)&cpu->address); +break ; + } + } +} +/* Perform service call. Return 0 on success, non-zero otherwise. */ int sclp_service_call (unsigned int command,void *sccb) {
lib/s390x/sclp.h +15 -0
@@ -101,6 +101,20 @@ typedef struct CPUEntry {uint8_t reserved1; } __attribute__((packed)) CPUEntry; +extern struct sclp_facilities sclp_facilities; + +struct sclp_facilities { +u64 has_sief2 :1 ; +}; + +/* +* test_bit() uses unsigned long ptrs so we give it the ptr to the +* address member and offset bits by 16. +*/ +enum sclp_cpu_feature_bit { +SCLP_CPU_FEATURE_SIEF2_BIT =16 +4 , +}; + typedef struct ReadInfo { SCCBHeader h; uint16_t rnmax;
@@ -274,6 +288,7 @@ void sclp_print(const char *str);void sclp_read_info (void );int sclp_get_cpu_num (void );CPUEntry *sclp_get_cpu_entries (void ); +void sclp_facilities_setup (void );int sclp_service_call (unsigned int command,void *sccb);void sclp_memory_setup (void );uint64_t get_ram_size (void );
Signature · 1 line
2.25.1
Re: [kvm-unit-tests PATCH 3/5] s390x: SCLP feature checking
Quoted 10 lines · On Tue, 17 Nov 2020 10:42:13 -0500 Janosch Frank <[email protected]> wrote:
Availability of SIE is announced via a feature bit in a SCLP info CPU entry. Let's add a framework that allows us to easily check for such facilities.
Signed-off-by Janosch Frank <[email protected]>--- lib/s390x/io.c | 1 + lib/s390x/sclp.c | 19 +++++++++++++++++++ lib/s390x/sclp.h | 15 +++++++++++++++ 3 files changed, 35 insertions(+)
(...)
lib/s390x/sclp.c CPUEntry *sclp_get_cpu_entries(void) · line 144
Quoted 12 lines
lib/s390x/sclp.c +12
-0+void sclp_facilities_setup (void ) +{ +unsigned short cpu0_addr =stap (); +CPUEntry *cpu; +int i; + +assert (read_info); + + cpu = (void *)read_info + read_info->offset_cpu; +for (i =0 ; i < read_info->entries_cpu; i++, cpu++) { +if (cpu->address == cpu0_addr) { + sclp_facilities.has_sief2 =test_bit_inv (SCLP_CPU_FEATURE_SIEF2_BIT , (void *)&cpu->address);
Can you wrap this? This line is really overlong.
(Also, just to understand: Is sief2 only indicated for cpu0, and not for the other cpus?)
Quoted 8 lines
lib/s390x/sclp.c +5
-0+break ; + } + } +} +/* Perform service call. Return 0 on success, non-zero otherwise. */ int sclp_service_call (unsigned int command,void *sccb) {
Re: [kvm-unit-tests PATCH 3/5] s390x: SCLP feature checking
Quoted 7 lines · Cornelia Huck
Quoted 4 lines · On Tue, 17 Nov 2020 10:42:13 -0500 Janosch Frank <[email protected]> wrote:
Availability of SIE is announced via a feature bit in a SCLP info CPU entry. Let's add a framework that allows us to easily check for such facilities.
Quoted 8 lines
Quoted 6 lines
Signed-off-by Janosch Frank <[email protected]>--- lib/s390x/io.c | 1 + lib/s390x/sclp.c | 19 +++++++++++++++++++ lib/s390x/sclp.h | 15 +++++++++++++++ 3 files changed, 35 insertions(+)(...)
Btw. I also wanted to add this to the struct sclp_facilities:
u64 reserved : 63:
Quoted 15 lines
lib/s390x/sclp.c CPUEntry *sclp_get_cpu_entries(void) · line 144
Quoted 13 lines
lib/s390x/sclp.c +12
-0+void sclp_facilities_setup (void ) +{ +unsigned short cpu0_addr =stap (); +CPUEntry *cpu; +int i; + +assert (read_info); + + cpu = (void *)read_info + read_info->offset_cpu; +for (i =0 ; i < read_info->entries_cpu; i++, cpu++) { +if (cpu->address == cpu0_addr) { + sclp_facilities.has_sief2 =test_bit_inv (SCLP_CPU_FEATURE_SIEF2_BIT , (void *)&cpu->address);Can you wrap this? This line is really overlong.
Sure
Quoted 3 lines
(Also, just to understand: Is sief2 only indicated for cpu0, and not for the other cpus?)
That's an excellent question I don't know the answer to. I had a look at the kernel's implementation of this and that's what they're doing so I figured they had a reason for it.
The documentation doesn't seem to say anything about that, but there's a lot of it I haven't yet read.
Quoted 10 lines
Quoted 9 lines
lib/s390x/sclp.c +5
-0+break ; + } + } +} +/* Perform service call. Return 0 on success, non-zero otherwise. */ int sclp_service_call (unsigned int command,void *sccb) {
Re: [kvm-unit-tests PATCH 3/5] s390x: SCLP feature checking
In reply to Janosch FrankQuoted 10 lines · Janosch Frank
Availability of SIE is announced via a feature bit in a SCLP info CPU entry. Let's add a framework that allows us to easily check for such facilities.
Signed-off-by Janosch Frank <[email protected]>--- lib/s390x/io.c | 1 + lib/s390x/sclp.c | 19 +++++++++++++++++++ lib/s390x/sclp.h | 15 +++++++++++++++ 3 files changed, 35 insertions(+)
[...]
Quoted 10 lines
lib/s390x/sclp.h +2
-0@@ -101,6 +101,20 @@ typedef struct CPUEntry {uint8_t reserved1; } __attribute__((packed)) CPUEntry; +extern struct sclp_facilities sclp_facilities; +
lib/s390x/sclp.h typedef struct CPUEntry { · line 115
Quoted 10 lines
lib/s390x/sclp.h +10
-0+struct sclp_facilities { +u64 has_sief2 :1 ; +}; + +/* +* test_bit() uses unsigned long ptrs so we give it the ptr to the +* address member and offset bits by 1> + */ +enum sclp_cpu_feature_bit { +SCLP_CPU_FEATURE_SIEF2_BIT =16 +4 , +};
That's kind of ugly ... why don't you simply replace the CPUEntry.features[] array with a bitfield, similar to what the kernel does with "struct sclp_core_entry" ?
Thomas
Re: [kvm-unit-tests PATCH 3/5] s390x: SCLP feature checking
Quoted 20 lines · Thomas Huth
Quoted 10 lines · Janosch Frank
Availability of SIE is announced via a feature bit in a SCLP info CPU entry. Let's add a framework that allows us to easily check for such facilities.
Signed-off-by Janosch Frank <[email protected]>--- lib/s390x/io.c | 1 + lib/s390x/sclp.c | 19 +++++++++++++++++++ lib/s390x/sclp.h | 15 +++++++++++++++ 3 files changed, 35 insertions(+)[...]
Quoted 8 lines
lib/s390x/sclp.h +0
-0@@ -101,6 +101,20 @@ typedef struct CPUEntry {uint8_t reserved1; } __attribute__((packed)) CPUEntry;
Quoted 16 lines
lib/s390x/sclp.h typedef struct CPUEntry { · line 116
Quoted 12 lines
lib/s390x/sclp.h +12
-0+extern struct sclp_facilities sclp_facilities; + +struct sclp_facilities { +u64 has_sief2 :1 ; +}; + +/* +* test_bit() uses unsigned long ptrs so we give it the ptr to the +* address member and offset bits by 1> + */ +enum sclp_cpu_feature_bit { +SCLP_CPU_FEATURE_SIEF2_BIT =16 +4 , +};That's kind of ugly ... why don't you simply replace the CPUEntry.features[] array with a bitfield, similar to what the kernel does with "struct
sclp_core_entry" ?
That's an excellent idea, will do!
Quoted 4 lines
Thomas
PATCH 4/5 s390x: sie: Add SIE to lib
In reply to Janosch FrankThis commit adds the definition of the SIE control block struct and the assembly to execute SIE and save/restore guest registers.
--- lib/s390x/asm-offsets.c | 13 +++ lib/s390x/asm/arch_def.h | 7 ++ lib/s390x/interrupt.c | 7 ++ lib/s390x/sie.h | 197 +++++++++++++++++++++++++++++++++++++++ s390x/cstart64.S | 56 +++++++++++ 5 files changed, 280 insertions(+) create mode 100644 lib/s390x/sie.h
lib/s390x/asm-offsets.c +13 -0
@@ -10,6 +10,7 @@#include <libcflat.h> #include <kbuild.h> #include <asm/arch_def.h> +#include <sie.h> int main (void ) {
@@ -71,6 +72,18 @@ int main(void)OFFSET (GEN_LC_ARS_SA , lowcore, ars_sa);OFFSET (GEN_LC_CRS_SA , lowcore, crs_sa);OFFSET (GEN_LC_PGM_INT_TDB , lowcore, pgm_int_tdb); +OFFSET (__SF_GPRS, stack_frame, gprs); +OFFSET (__SF_SIE_CONTROL, stack_frame, empty1[0 ]); +OFFSET (__SF_SIE_SAVEAREA, stack_frame, empty1[1 ]); +OFFSET (__SF_SIE_REASON, stack_frame, empty1[2 ]); +OFFSET (__SF_SIE_FLAGS, stack_frame, empty1[3 ]); +OFFSET (SIE_SAVEAREA_HOST_GRS , vm_save_area, host.grs[0 ]); +OFFSET (SIE_SAVEAREA_HOST_FPRS , vm_save_area, host.fprs[0 ]); +OFFSET (SIE_SAVEAREA_HOST_FPC , vm_save_area, host.fpc); +OFFSET (SIE_SAVEAREA_GUEST_GRS , vm_save_area, guest.grs[0 ]); +OFFSET (SIE_SAVEAREA_GUEST_FPRS , vm_save_area, guest.fprs[0 ]); +OFFSET (SIE_SAVEAREA_GUEST_FPC , vm_save_area, guest.fpc); +return 0 ; }
lib/s390x/asm/arch_def.h +7 -0
@@ -10,6 +10,13 @@ #ifndef _ASM_S390X_ARCH_DEF_H_ #define _ASM_S390X_ARCH_DEF_H_ +struct stack_frame { + unsigned long back_chain; + unsigned long empty1[5]; + unsigned long gprs[10]; + unsigned int empty2[8]; +}; + struct psw { uint64_t mask; uint64_t addr;
lib/s390x/interrupt.c +7 -0
@@ -13,6 +13,7 @@#include <asm/barrier.h> #include <sclp.h> #include <interrupt.h> +#include <sie.h> static bool pgm_int_expected;static bool ext_int_expected;
@@ -59,6 +60,12 @@ void register_pgm_cleanup_func(void (*f)(void))static void fixup_pgm_int (void ) { +/* If we have an error on SIE we directly move to sie_exit */ +if (lc->pgm_old_psw.addr >= (uint64_t )&sie_entry && + lc->pgm_old_psw.addr <= (uint64_t )&sie_entry +10 ) { + lc->pgm_old_psw.addr = (uint64_t )&sie_exit; + } +switch (lc->pgm_int_code) {case PGM_INT_CODE_PRIVILEGED_OPERATION :/* Normal operation is in supervisor state, so this exception
lib/s390x/sie.h new file +197 -0
197 lines not on this page · raw message
s390x/cstart64.S +56 -0
62 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH 5/5 s390x: sie: Add first SIE test
In reply to Janosch FrankLet's check if we get the correct interception data on a few diags. This commit is more of an addition of boilerplate code than a real test.
--- s390x/Makefile | 1 + s390x/sie.c | 125 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 126 insertions(+) create mode 100644 s390x/sie.c
s390x/Makefile +1 -0
@@ -19,6 +19,7 @@ tests += $(TEST_DIR)/smp.elf tests += $(TEST_DIR)/sclp.elf tests += $(TEST_DIR)/css.elf tests += $(TEST_DIR)/uv-guest.elf +tests += $(TEST_DIR)/sie.elf tests_binary = $(patsubst %.elf,%.bin,$(tests)) ifneq ($(HOST_KEY_DOCUMENT),)
s390x/sie.c new file +125 -0
125 lines not on this page · raw message
Signature · 1 line
2.25.1