S390x: CPU Topology Information
v4 cover S390x: CPU Topology Information
Hi,
new version of the series with corrections.
When facility 11 is available inside the S390x architecture, 2 new instructions are available: PTF and STSI with function code 15.
Let's check their availability in QEMU/KVM and their coherence with the CPU topology provided to the QEMU -smp parameter and as argument for the test.
To run these tests successfully you will need both the Linux and the QEMU patches, at least the following or newer patches:
https://lkml.org/lkml/2021/8/3/201 https://lists.nongnu.org/archive/html/qemu-s390x/2021-07/msg00165.html
Then if you have the text you can run directly the unit test or directly start QEMU with:
# ./s390x-run s390x/topology.elf \ -smp 5,drawers=2,books=3,sockets=4,cores=4,maxcpus=96 \ -append "-d 2 -b 3 -s 4 -c 4 -m 96"
If you do not have the patches you can still use the test but only with the first two topology levels like in:
# ./s390x-run s390x/topology.elf \ -smp 5,sockets=24,cores=4,maxcpus=96 \ -append "-s 24 -c 4 -m 96"
Of course the declaration of the number of socket and core must be coherent.
Regards,
Pierre
Pierre Morel (4):
s390x: lib: Add SCLP toplogy nested level
s390x: stsi: Define vm_is_kvm to be used in different tests
s390x: topology: Check the Perform Topology Function
s390x: topology: Checking Configuration Topology Information
lib/s390x/sclp.c | 6 + lib/s390x/sclp.h | 4 +- lib/s390x/stsi.h | 76 ++++++++++ lib/s390x/vm.c | 56 ++++++- lib/s390x/vm.h | 3 + s390x/Makefile | 1 + s390x/stsi.c | 23 +-- s390x/topology.c | 346 ++++++++++++++++++++++++++++++++++++++++++++ s390x/unittests.cfg | 4 + 9 files changed, 495 insertions(+), 24 deletions(-) create mode 100644 lib/s390x/stsi.h create mode 100644 s390x/topology.c
Signature · 45 lines
2.27.0 Changelog: From V2: - Copyrights modifications, assert for allocation failures (Claudio) - adding a vm_is_lpar and modification of vm_is_kvm (Janosh) - Check if the test in running in KVM (Janosch) - patch on "Simplify stsi_get_fc and move it to library" pushed separatly - replace named level with abstracted topology levels to get rid of a possible naming controversy (Pierre) - Better checks and new checks for STSI(15,1,x) (Pierre) From V1: - Simplify the stsi_get_fc function when pushing it into lib (Janosch) - Simplify PTF inline assembly as PTF instruction does not use RRE second argument (Claudio) - Rename Test global name (Claudio, Janosch) - readibility, naming for PTF_REQ_* and removed unused globals (Janosch) - skipping tests which could fail when run on LPAR (Janosh) - Missing prefix_pop (Janosch)
PATCH v4 1/4 s390x: lib: Add SCLP toplogy nested level
The maximum CPU Topology nested level is available with the SCLP READ_INFO command inside the byte at offset 15 of the ReadInfo structure.
Let's return this information to check the number of topology nested information available with the STSI 15.1.x instruction.
--- lib/s390x/sclp.c | 6 ++++++ lib/s390x/sclp.h | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-)
lib/s390x/sclp.c +6 -0
@@ -128,6 +128,12 @@ int sclp_get_cpu_num(void)return read_info->entries_cpu; } +int sclp_get_stsi_parm (void ) +{ +assert (read_info); +return read_info->stsi_parm; +} +CPUEntry *sclp_get_cpu_entries (void ) {assert (read_info);
lib/s390x/sclp.h +3 -1
@@ -146,7 +146,8 @@ typedef struct ReadInfo {SCCBHeader h;uint16_t rnmax;uint8_t rnsize; -uint8_t _reserved1[16 -11 ];/* 11-15 */ +uint8_t _reserved1[15 -11 ];/* 11-14 */ +uint8_t stsi_parm;uint16_t entries_cpu;/* 16-17 */ uint16_t offset_cpu;/* 18-19 */ uint8_t _reserved2[24 -20 ];/* 20-23 */
@@ -323,6 +324,7 @@ void sclp_console_setup(void);void sclp_print (const char *str);void sclp_read_info (void );int sclp_get_cpu_num (void ); +int sclp_get_stsi_parm (void );CPUEntry *sclp_get_cpu_entries (void );void sclp_facilities_setup (void );int sclp_service_call (unsigned int command,void *sccb);
Signature · 1 line
2.27.0
PATCH v4 2/4 s390x: stsi: Define vm_is_kvm to be used in different tests
In reply to Pierre MorelWe need in several tests to check if the VM we are running in is KVM.
Let's add the test.
To check the VM type we use the STSI 3.2.2 instruction, let's define it's response structure in a central header.
--- lib/s390x/stsi.h | 32 +++++++++++++++++++++++++++ lib/s390x/vm.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++-- lib/s390x/vm.h | 3 +++ s390x/stsi.c | 23 ++------------------ 4 files changed, 91 insertions(+), 23 deletions(-) create mode 100644 lib/s390x/stsi.h
lib/s390x/stsi.h new file +32 -0
@@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* Structures used to Store System Information +* +* Copyright IBM Corp. 2022 +*/ + +#ifndef _S390X_STSI_H_ +#define _S390X_STSI_H_ + +struct sysinfo_3_2_2 { +uint8_t reserved[31 ]; +uint8_t count; +struct { +uint8_t reserved2[4 ]; +uint16_t total_cpus; +uint16_t conf_cpus; +uint16_t standby_cpus; +uint16_t reserved_cpus; +uint8_t name[8 ]; +uint32_t caf; +uint8_t cpi[16 ]; +uint8_t reserved5[3 ]; +uint8_t ext_name_encoding; +uint32_t reserved3; +uint8_t uuid[16 ]; + } vm[8 ]; +uint8_t reserved4[1504 ]; +uint8_t ext_names[8 ][256 ]; +}; + +#endif /* _S390X_STSI_H_ */
lib/s390x/vm.c +54 -2
72 lines not on this page · raw message
lib/s390x/vm.h +3 -0
@@ -9,5 +9,8 @@#define _S390X_VM_H_bool vm_is_tcg (void ); +bool vm_is_kvm (void ); +bool vm_is_vm (void ); +bool vm_is_lpar (void );#endif /* _S390X_VM_H_ */
s390x/stsi.c +2 -21
@@ -13,27 +13,8 @@#include <asm/asm-offsets.h> #include <asm/interrupt.h> #include <smp.h> +#include "stsi.h" -struct stsi_322 { -uint8_t reserved[31 ]; -uint8_t count; -struct { -uint8_t reserved2[4 ]; -uint16_t total_cpus; -uint16_t conf_cpus; -uint16_t standby_cpus; -uint16_t reserved_cpus; -uint8_t name[8 ]; -uint32_t caf; -uint8_t cpi[16 ]; -uint8_t reserved5[3 ]; -uint8_t ext_name_encoding; -uint32_t reserved3; -uint8_t uuid[16 ]; - } vm[8 ]; -uint8_t reserved4[1504 ]; -uint8_t ext_names[8 ][256 ]; -}; static uint8_t pagebuf[PAGE_SIZE * 2] __attribute__((aligned(PAGE_SIZE * 2)));static void test_specs (void )
@@ -91,7 +72,7 @@ static void test_3_2_2(void)/* EBCDIC for "KVM/" */ const uint8_t cpi_kvm[] = {0xd2 ,0xe5 ,0xd4 ,0x61 };const char vm_name_ext[] ="kvm-unit-test" ; -struct stsi_322 *data = (void *)pagebuf; +struct sysinfo_3_2_2 *data = (void *)pagebuf;report_prefix_push ("3.2.2" );
Signature · 1 line
2.27.0
Re: [kvm-unit-tests PATCH v4 2/4] s390x: stsi: Define vm_is_kvm to be used in different tests
Quoted 3 lines · Pierre Morel
We need in several tests to check if the VM we are running in is KVM.
Let's add the test.
Several tests are in need of a way to check on which hypervisor and virtualization level they are running on to be able to fence certain tests. This patch adds functions that return true if a vm is running under KVM, LPAR or generally as a level 2 guest.
Quoted 2 lines
To check the VM type we use the STSI 3.2.2 instruction, let's
To check if we're running under KVM we...
Quoted 1 line
define it's response structure in a central header.
Since we already have a stsi test that defines the 3.2.2 structure let's move the struct from the test into a new library header.
Quoted 17 lines
Signed-off-by Pierre Morel <[email protected]>--- lib/s390x/stsi.h | 32 +++++++++++++++++++++++++++ lib/s390x/vm.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++-- lib/s390x/vm.h | 3 +++ s390x/stsi.c | 23 ++------------------ 4 files changed, 91 insertions(+), 23 deletions(-)create mode 100644
lib/s390x/stsi.hlib/s390x/stsi.h new file +1
-0@@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */
lib/s390x/stsi.h line 11
Quoted 10 lines
lib/s390x/stsi.h new file +10
-0+/* +* Structures used to Store System Information +* +* Copyright IBM Corp. 2022 +*/ + +#ifndef _S390X_STSI_H_ +#define _S390X_STSI_H_ + +struct sysinfo_3_2_2 {
Any particular reason why you renamed this?
Quoted 89 lines
lib/s390x/stsi.h new file +21
-0+uint8_t reserved[31 ]; +uint8_t count; +struct { +uint8_t reserved2[4 ]; +uint16_t total_cpus; +uint16_t conf_cpus; +uint16_t standby_cpus; +uint16_t reserved_cpus; +uint8_t name[8 ]; +uint32_t caf; +uint8_t cpi[16 ]; +uint8_t reserved5[3 ]; +uint8_t ext_name_encoding; +uint32_t reserved3; +uint8_t uuid[16 ]; + } vm[8 ]; +uint8_t reserved4[1504 ]; + uint8_t ext_names[8][256]; +}; + +#endif /* _S390X_STSI_H_ */ lib/s390x/vm.c +43
-2@@ -12,6 +12,7 @@#include <alloc_page.h> #include <asm/arch_def.h> #include "vm.h" +#include "stsi.h" /** * Detect whether we are running with TCG (instead of KVM) @@ -26,9 +27,13 @@ bool vm_is_tcg(void)if (initialized)return is_tcg; - buf =alloc_page (); -if (!buf) +if (!vm_is_vm ()) { + initialized = true;return false; + } + + buf =alloc_page (); +assert (buf);if (stsi (buf,1 ,1 ,1 )) goto out;@@ -43,3 +48,50 @@ out:free_page (buf);return is_tcg; } + +/** +* Detect whether we are running with KVM +*/ + +bool vm_is_kvm (void ) +{ +/* EBCDIC for "KVM/" */ +const uint8_t kvm_ebcdic[] = {0xd2 ,0xe5 ,0xd4 ,0x61 }; +static bool initialized; +static bool is_kvm; +struct sysinfo_3_2_2 *stsi_322; + +if (initialized) +return is_kvm; + +if (!vm_is_vm () ||vm_is_tcg ()) { + initialized = true; +return is_kvm; + } + + stsi_322 =alloc_page (); +assert (stsi_322); + +if (stsi (stsi_322,3 ,2 ,2 )) + goto out; + +/* +* If the manufacturer string is "KVM/" in EBCDIC, then we +* are on KVM. +*/ + is_kvm = !memcmp (&stsi_322->vm[0 ].cpi, kvm_ebcdic,sizeof (kvm_ebcdic)); + initialized = true; +out: +free_page (stsi_322); +return is_kvm;
lib/s390x/vm.c out: · line 96
Quoted 10 lines
lib/s390x/vm.c +10
-0+} + +bool vm_is_lpar (void ) +{ +return stsi_get_fc () ==2 ; +} + +bool vm_is_vm (void ) +{ +return stsi_get_fc () ==3 ;
This would be true when running under z/VM, no?
I.e. what you're testing here is that we're a level 2 guest and hence the naming could be improved.
Also: what if we're under VSIE where we would be > 3?
Quoted 19 lines
lib/s390x/vm.c +1
-0+}lib/s390x/vm.h +3
-0@@ -9,5 +9,8 @@#define _S390X_VM_H_bool vm_is_tcg (void ); +bool vm_is_kvm (void ); +bool vm_is_vm (void ); +bool vm_is_lpar (void );#endif /* _S390X_VM_H_ */ s390x/stsi.c +0
-0
s390x/stsi.c line 16
Quoted 4 lines
s390x/stsi.c +1
-0@@ -13,27 +13,8 @@#include <asm/asm-offsets.h> #include <asm/interrupt.h> #include <smp.h> +#include "stsi.h"
#include <stsi.h>
We're not in the lib.
Quoted 33 lines
s390x/stsi.c +1
-21-struct stsi_322 { -uint8_t reserved[31 ]; -uint8_t count; -struct { -uint8_t reserved2[4 ]; -uint16_t total_cpus; -uint16_t conf_cpus; -uint16_t standby_cpus; -uint16_t reserved_cpus; -uint8_t name[8 ]; -uint32_t caf; -uint8_t cpi[16 ]; -uint8_t reserved5[3 ]; -uint8_t ext_name_encoding; -uint32_t reserved3; -uint8_t uuid[16 ]; - } vm[8 ]; -uint8_t reserved4[1504 ]; -uint8_t ext_names[8 ][256 ]; -}; static uint8_t pagebuf[PAGE_SIZE * 2] __attribute__((aligned(PAGE_SIZE * 2)));static void test_specs (void )@@ -91,7 +72,7 @@ static void test_3_2_2(void)/* EBCDIC for "KVM/" */ const uint8_t cpi_kvm[] = {0xd2 ,0xe5 ,0xd4 ,0x61 };const char vm_name_ext[] ="kvm-unit-test" ; -struct stsi_322 *data = (void *)pagebuf; +struct sysinfo_3_2_2 *data = (void *)pagebuf;report_prefix_push ("3.2.2" );
Re: [kvm-unit-tests PATCH v4 2/4] s390x: stsi: Define vm_is_kvm to be used in different tests
Quoted 11 lines · Janosch Frank
Quoted 11 lines
lib/s390x/stsi.h new file +5
-0@@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* Structures used to Store System Information +* +* Copyright IBM Corp. 2022
Quoted 8 lines
lib/s390x/stsi.h line 11
Quoted 6 lines
lib/s390x/stsi.h new file +6
-0+*/ + +#ifndef _S390X_STSI_H_ +#define _S390X_STSI_H_ + +struct sysinfo_3_2_2 {Any particular reason why you renamed this?
Stumbled across this as well. I think this makes it consistent with Linux' arch/s390/include/asm/sysinfo.h.
The PoP, on the other hand, calls it SYSIB, so this at least resolves the inconsistency between kvm-unit-tests and Linux.
Re: [kvm-unit-tests PATCH v4 2/4] s390x: stsi: Define vm_is_kvm to be used in different tests
Quoted 21 lines · Nico Boehr
Quoted 11 lines · Janosch Frank
Quoted 11 lines
lib/s390x/stsi.h new file +5
-0@@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* Structures used to Store System Information +* +* Copyright IBM Corp. 2022 Quoted 8 lines
lib/s390x/stsi.h line 11
Quoted 6 lines
lib/s390x/stsi.h new file +6
-0+*/ + +#ifndef _S390X_STSI_H_ +#define _S390X_STSI_H_ + +struct sysinfo_3_2_2 {Any particular reason why you renamed this?
Quoted 6 lines
Stumbled across this as well. I think this makes it consistent with Linux'
arch/s390/include/asm/sysinfo.h.The PoP, on the other hand, calls it SYSIB, so this at least resolves the inconsistency between kvm-unit-tests and Linux.
In fact I do not know why I renamed it probably because I coded the next patches first and used sysinfo in it. QEMU calls these structures SysIB so for me we do as you want.
Signature · 2 lines
Pierre Morel IBM Lab Boeblingen
Re: [kvm-unit-tests PATCH v4 2/4] s390x: stsi: Define vm_is_kvm to be used in different tests
In reply to Janosch FrankQuoted 11 lines · Janosch Frank
Quoted 3 lines · Pierre Morel
We need in several tests to check if the VM we are running in is KVM.
Let's add the test.Several tests are in need of a way to check on which hypervisor and virtualization level they are running on to be able to fence certain tests. This patch adds functions that return true if a vm is running under KVM, LPAR or generally as a level 2 guest.
Quoted 2 lines
To check the VM type we use the STSI 3.2.2 instruction, let's
To check if we're running under KVM we...
OK
Quoted 4 lines
Quoted 2 lines
define it's response structure in a central header.
Since we already have a stsi test that defines the 3.2.2 structure let's move the struct from the test into a new library header.
OK
Quoted 22 lines
Quoted 22 lines
Signed-off-by Pierre Morel <[email protected]>---
lib/s390x/stsi.h| 32 +++++++++++++++++++++++++++ lib/s390x/vm.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++-- lib/s390x/vm.h | 3 +++
s390x/stsi.c | 23 ++------------------4 files changed, 91 insertions(+), 23 deletions(-)create mode 100644
lib/s390x/stsi.hlib/s390x/stsi.h new file +5
-0@@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* Structures used to Store System Information +* +* Copyright IBM Corp. 2022
Quoted 8 lines
lib/s390x/stsi.h line 11
Quoted 6 lines
lib/s390x/stsi.h new file +6
-0+*/ + +#ifndef _S390X_STSI_H_ +#define _S390X_STSI_H_ + +struct sysinfo_3_2_2 {Any particular reason why you renamed this?
In addition to what I answered to Nico:
I found stsi_3_2_2 better to describe a function calling STSI(3,2,2) than the result of the STSI(3,2,2) instruction, the SYStem Information Block.
Quoted 92 lines
Quoted 92 lines
lib/s390x/stsi.h new file +21
-0+ uint8_t reserved[31]; + uint8_t count; + struct { + uint8_t reserved2[4]; + uint16_t total_cpus; + uint16_t conf_cpus; + uint16_t standby_cpus; + uint16_t reserved_cpus; + uint8_t name[8]; + uint32_t caf; + uint8_t cpi[16]; + uint8_t reserved5[3]; + uint8_t ext_name_encoding; + uint32_t reserved3; + uint8_t uuid[16]; + } vm[8]; + uint8_t reserved4[1504]; + uint8_t ext_names[8][256]; +}; + +#endif /* _S390X_STSI_H_ */ lib/s390x/vm.c +39
-2@@ -12,6 +12,7 @@ #include <alloc_page.h> #include <asm/arch_def.h> #include "vm.h" +#include "stsi.h" /*** Detect whether we are running with TCG (instead of KVM) @@ -26,9 +27,13 @@ bool vm_is_tcg(void) if (initialized) return is_tcg; - buf = alloc_page(); - if (!buf) + if (!vm_is_vm()) { + initialized = true; return false; + } + + buf = alloc_page(); + assert(buf); if (stsi(buf, 1, 1, 1)) goto out;@@ -43,3 +48,50 @@ out: free_page(buf); return is_tcg; } + +/** +* Detect whether we are running with KVM +*/ + +bool vm_is_kvm (void ) +{ + /* EBCDIC for "KVM/" */ + const uint8_t kvm_ebcdic[] = { 0xd2, 0xe5, 0xd4, 0x61 }; + static bool initialized; + static bool is_kvm; + struct sysinfo_3_2_2 *stsi_322; + + if (initialized) + return is_kvm; + + if (!vm_is_vm() || vm_is_tcg()) { + initialized = true; + return is_kvm; + } + + stsi_322 = alloc_page(); + assert(stsi_322); + + if (stsi(stsi_322, 3, 2, 2)) + goto out; + + /* + * If the manufacturer string is "KVM/" in EBCDIC, then we + * are on KVM. + */ + is_kvm = !memcmp(&stsi_322->vm[0].cpi, kvm_ebcdic,
sizeof(kvm_ebcdic));
+ initialized = true;lib/s390x/vm.c +7
-0+out: + free_page(stsi_322); + return is_kvm; +} + +bool vm_is_lpar (void ) +{
Quoted 8 lines
lib/s390x/vm.c out: · line 96
Quoted 6 lines
+ return
stsi_get_fc()== 2;lib/s390x/vm.c +5
-0+} + +bool vm_is_vm (void ) +{ + return stsi_get_fc() == 3;This would be true when running under z/VM, no?
yes
Quoted 2 lines
I.e. what you're testing here is that we're a level 2 guest and hence the naming could be improved.
STSI(0,x,x) used by stsi_get_fc() returns the current configuration level number which can be one of: basic machine (1), LPAR(2) or VM(3)
by the way stsi_get_fc() should probably better be named stsi_get_cfglevel() or something like that.
Quoted 2 lines
Also: what if we're under VSIE where we would be > 3?
No other configuration level is defined in the architecture than (1,2,3)
Quoted 25 lines
Quoted 18 lines
lib/s390x/vm.c +1
-0+}lib/s390x/vm.h +3
-0@@ -9,5 +9,8 @@ #define _S390X_VM_H_ bool vm_is_tcg(void); +bool vm_is_kvm (void ); +bool vm_is_vm (void ); +bool vm_is_lpar (void ); #endif /* _S390X_VM_H_ */s390x/stsi.c +0
-0s390x/stsi.c line 16
Quoted 4 lines
s390x/stsi.c +1
-0@@ -13,27 +13,8 @@ #include <asm/asm-offsets.h> #include <asm/interrupt.h> #include <smp.h> +#include "stsi.h" #include <
stsi.h>
Quoted 1 line
We're not in the lib.
OK
Quoted 22 lines
Quoted 22 lines
s390x/stsi.c +0
-20-struct stsi_322 { - uint8_t reserved[31]; - uint8_t count; - struct { - uint8_t reserved2[4]; - uint16_t total_cpus; - uint16_t conf_cpus; - uint16_t standby_cpus; - uint16_t reserved_cpus; - uint8_t name[8]; - uint32_t caf; - uint8_t cpi[16]; - uint8_t reserved5[3]; - uint8_t ext_name_encoding; - uint32_t reserved3; - uint8_t uuid[16]; - } vm[8]; - uint8_t reserved4[1504]; - uint8_t ext_names[8][256]; -}; static uint8_t pagebuf[PAGE_SIZE * 2] __attribute__((aligned(PAGE_SIZE * 2)));
Quoted 9 lines
s390x/stsi.c static void test_3_2_2(void) · line 76
Quoted 8 lines
s390x/stsi.c +1
-1static void test_specs(void)@@ -91,7 +72,7 @@ static void test_3_2_2(void) /* EBCDIC for "KVM/" */ const uint8_t cpi_kvm[] = { 0xd2, 0xe5, 0xd4, 0x61 }; const char vm_name_ext[] = "kvm-unit-test"; - struct stsi_322 *data = (void *)pagebuf; + struct sysinfo_3_2_2 *data = (void *)pagebuf; report_prefix_push("3.2.2");
Thanks for the review,
Pierre
Signature · 2 lines
Pierre Morel IBM Lab Boeblingen
Re: [kvm-unit-tests PATCH v4 2/4] s390x: stsi: Define vm_is_kvm to be used in different tests
In reply to Pierre MorelQuoted 24 lines · Pierre Morel
We need in several tests to check if the VM we are running in is KVM.
Let's add the test.To check the VM type we use the STSI 3.2.2 instruction, let's define it's response structure in a central header.
Signed-off-by Pierre Morel <[email protected]>---
lib/s390x/stsi.h | 32 +++++++++++++++++++++++++++ lib/s390x/vm.c | 56
++++++++++++++++++++++++++++++++++++++++++++++--
lib/s390x/vm.h | 3 +++
s390x/stsi.c | 23 ++------------------4 files changed, 91 insertions(+), 23 deletions(-)create mode 100644
lib/s390x/stsi.hlib/s390x/stsi.h new file +0
-0
lib/s390x/stsi.h line 1
Quoted 1 line
lib/s390x/stsi.h new file +1
-0@@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */
This was taken from stsi.c which is GPL 2 only, so this probably should be as well.
Quoted 36 lines
lib/s390x/vm.c +1
-0@@ -12,6 +12,7 @@ #include <alloc_page.h> #include <asm/arch_def.h> #include "vm.h" +#include "stsi.h"
/**
* Detect whether we are running with TCG (instead of KVM)lib/s390x/vm.c +0
-0@@ -26,9 +27,13 @@ bool vm_is_tcg(void) if (initialized) return is_tcg;
- buf =alloc_page();
- if (!buf)
+ if (!vm_is_vm()) {
+ initialized = true;
return false;lib/s390x/vm.c +1
-0@@ -12,6 +12,7 @@ #include <alloc_page.h> #include <asm/arch_def.h> #include "vm.h" +#include "stsi.h"
/**
* Detect whether we are running with TCG (instead of KVM)lib/s390x/vm.c +0
-0@@ -26,9 +27,13 @@ bool vm_is_tcg(void) if (initialized) return is_tcg;
Quoted 6 lines
- buf =alloc_page();
- if (!buf)
+ if (!vm_is_vm()) {
+ initialized = true;
return false;
I would personally prefer return is_tcg here to make it obvious we're relying on the previous initalization to false for subsequent calls.
Quoted 8 lines
+ }
+
+ buf =alloc_page();
+ assert(buf);
if (stsi(buf, 1, 1, 1))
goto out;
lib/s390x/vm.c out: · line 55
Quoted 8 lines
lib/s390x/vm.c +5
-0@@ -43,3 +48,50 @@ out: free_page(buf); return is_tcg; } + +/** +* Detect whether we are running with KVM +*/ +
No newline here.
lib/s390x/vm.c out: · line 61
Quoted 6 lines
lib/s390x/vm.c +6
-0+bool vm_is_kvm (void ) +{ + /* EBCDIC for "KVM/" */ + const uint8_t kvm_ebcdic[] = { 0xd2, 0xe5, 0xd4, 0x61 }; + static bool initialized; + static bool is_kvm;
Might make sense to initizalize these to false to make it consistent with vm_is_tcg().
Re: [kvm-unit-tests PATCH v4 2/4] s390x: stsi: Define vm_is_kvm to be used in different tests
Quoted 67 lines · Nico Boehr
Quoted 24 lines · Pierre Morel
We need in several tests to check if the VM we are running in is KVM.
Let's add the test.To check the VM type we use the STSI 3.2.2 instruction, let's define it's response structure in a central header.
Signed-off-by Pierre Morel <[email protected]>--- lib/s390x/stsi.h | 32 +++++++++++++++++++++++++++ lib/s390x/vm.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++-- lib/s390x/vm.h | 3 +++ s390x/stsi.c | 23 ++------------------ 4 files changed, 91 insertions(+), 23 deletions(-)create mode 100644
lib/s390x/stsi.hlib/s390x/stsi.h new file +0
-0lib/s390x/stsi.h line 1
Quoted 1 line
lib/s390x/stsi.h new file +1
-0@@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ This was taken from
stsi.cwhich is GPL 2 only, so this probably should be as well.Quoted 37 lines
lib/s390x/vm.c +3
-2@@ -12,6 +12,7 @@ #include <alloc_page.h> #include <asm/arch_def.h> #include "vm.h" +#include "stsi.h" /*** Detect whether we are running with TCG (instead of KVM) @@ -26,9 +27,13 @@ bool vm_is_tcg(void) if (initialized) return is_tcg; - buf = alloc_page(); - if (!buf) + if (!vm_is_vm()) { + initialized = true; return false;lib/s390x/vm.c +1
-0@@ -12,6 +12,7 @@ #include <alloc_page.h> #include <asm/arch_def.h> #include "vm.h" +#include "stsi.h" /*** Detect whether we are running with TCG (instead of KVM) @@ -26,9 +27,13 @@ bool vm_is_tcg(void) if (initialized) return is_tcg;
Quoted 8 lines
lib/s390x/vm.c bool vm_is_tcg(void) · line 32
Quoted 5 lines
lib/s390x/vm.c +2
-2- buf = alloc_page(); - if (!buf) + if (!vm_is_vm()) { + initialized = true; return false;I would personally prefer return
is_tcghere to make it obvious we're relying on the previous initalization to false for subsequent calls.
OK
Quoted 6 lines
Quoted 6 lines
lib/s390x/vm.c +4
-0+ } + + buf = alloc_page(); + assert(buf);
Quoted 13 lines
lib/s390x/vm.c out: · line 55
Quoted 11 lines
lib/s390x/vm.c +5
-0if (stsi(buf, 1, 1, 1)) goto out;@@ -43,3 +48,50 @@ out: free_page(buf); return is_tcg; } + +/** +* Detect whether we are running with KVM +*/ +No newline here.
ok
Quoted 11 lines
lib/s390x/vm.c out: · line 61
Quoted 7 lines
lib/s390x/vm.c +6
-0+bool vm_is_kvm (void ) +{ + /* EBCDIC for "KVM/" */ + const uint8_t kvm_ebcdic[] = { 0xd2, 0xe5, 0xd4, 0x61 }; + static bool initialized; + static bool is_kvm;Might make sense to initizalize these to false to make it consistent with
vm_is_tcg().
OK
Signature · 2 lines
Pierre Morel IBM Lab Boeblingen
Re: [kvm-unit-tests PATCH v4 2/4] s390x: stsi: Define vm_is_kvm to be used in different tests
In reply to Pierre MorelQuoted 83 lines · On Tue, 8 Feb 2022 14:27:07 +0100 Pierre Morel <[email protected]> wrote:
We need in several tests to check if the VM we are running in is KVM.
Let's add the test.To check the VM type we use the STSI 3.2.2 instruction, let's define it's response structure in a central header.
Signed-off-by Pierre Morel <[email protected]>--- lib/s390x/stsi.h | 32 +++++++++++++++++++++++++++ lib/s390x/vm.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++-- lib/s390x/vm.h | 3 +++ s390x/stsi.c | 23 ++------------------ 4 files changed, 91 insertions(+), 23 deletions(-) create mode 100644 lib/s390x/stsi.hlib/s390x/stsi.h new file +32
-0@@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* Structures used to Store System Information +* +* Copyright IBM Corp. 2022 +*/ + +#ifndef _S390X_STSI_H_ +#define _S390X_STSI_H_ + +struct sysinfo_3_2_2 { +uint8_t reserved[31 ]; +uint8_t count; +struct { +uint8_t reserved2[4 ]; +uint16_t total_cpus; +uint16_t conf_cpus; +uint16_t standby_cpus; +uint16_t reserved_cpus; +uint8_t name[8 ]; +uint32_t caf; +uint8_t cpi[16 ]; +uint8_t reserved5[3 ]; +uint8_t ext_name_encoding; +uint32_t reserved3; +uint8_t uuid[16 ]; + } vm[8 ]; +uint8_t reserved4[1504 ]; +uint8_t ext_names[8 ][256 ]; +}; + +#endif /* _S390X_STSI_H_ */ lib/s390x/vm.c +7
-2@@ -12,6 +12,7 @@#include <alloc_page.h> #include <asm/arch_def.h> #include "vm.h" +#include "stsi.h" /** * Detect whether we are running with TCG (instead of KVM) @@ -26,9 +27,13 @@ bool vm_is_tcg(void)if (initialized)return is_tcg; - buf =alloc_page (); -if (!buf) +if (!vm_is_vm ()) { + initialized = true;return false; + } + + buf =alloc_page (); +assert (buf);if (stsi (buf,1 ,1 ,1 )) goto out;
lib/s390x/vm.c out: · line 56
Quoted 9 lines
lib/s390x/vm.c +6
-0@@ -43,3 +48,50 @@ out:free_page (buf);return is_tcg; } + +/** +* Detect whether we are running with KVM +*/ + +bool vm_is_kvm (void )
I think this is too messy
I think a cleaner approach would be to have one "detect_environment" function to call stsi and find out which environment we are running on.
then the various vm_is_* would just be something like
bool vm_is_kvm(void)
{
return detect_environment() == VM_IS_KVM;
}obviously the detect_environment function would call stsi only once and then cache the result.
bonus, we could make that function public too, so e.g. a testcase could do a switch, instead of having to do a series of nested ifs
Quoted 28 lines
lib/s390x/vm.c +28
-0+{ +/* EBCDIC for "KVM/" */ +const uint8_t kvm_ebcdic[] = {0xd2 ,0xe5 ,0xd4 ,0x61 }; +static bool initialized; +static bool is_kvm; +struct sysinfo_3_2_2 *stsi_322; + +if (initialized) +return is_kvm; + +if (!vm_is_vm () ||vm_is_tcg ()) { + initialized = true; +return is_kvm; + } + + stsi_322 =alloc_page (); +assert (stsi_322); + +if (stsi (stsi_322,3 ,2 ,2 )) + goto out; + +/* +* If the manufacturer string is "KVM/" in EBCDIC, then we +* are on KVM. +*/ + is_kvm = !memcmp (&stsi_322->vm[0 ].cpi, kvm_ebcdic,sizeof (kvm_ebcdic)); + initialized = true; +out:
lib/s390x/vm.c out: · line 94
Quoted 10 lines
lib/s390x/vm.c +10
-0+free_page (stsi_322); +return is_kvm; +} + +bool vm_is_lpar (void ) +{ +return stsi_get_fc () ==2 ; +} + +bool vm_is_vm (void )
is it enough to call it vm? maybe zvm? I don't have a strong opinion, though
Quoted 58 lines
lib/s390x/vm.c +3
-0+{ +return stsi_get_fc () ==3 ; +}lib/s390x/vm.h +3
-0@@ -9,5 +9,8 @@#define _S390X_VM_H_bool vm_is_tcg (void ); +bool vm_is_kvm (void ); +bool vm_is_vm (void ); +bool vm_is_lpar (void );#endif /* _S390X_VM_H_ */ s390x/stsi.c +2
-21@@ -13,27 +13,8 @@#include <asm/asm-offsets.h> #include <asm/interrupt.h> #include <smp.h> +#include "stsi.h" -struct stsi_322 { -uint8_t reserved[31 ]; -uint8_t count; -struct { -uint8_t reserved2[4 ]; -uint16_t total_cpus; -uint16_t conf_cpus; -uint16_t standby_cpus; -uint16_t reserved_cpus; -uint8_t name[8 ]; -uint32_t caf; -uint8_t cpi[16 ]; -uint8_t reserved5[3 ]; -uint8_t ext_name_encoding; -uint32_t reserved3; -uint8_t uuid[16 ]; - } vm[8 ]; -uint8_t reserved4[1504 ]; -uint8_t ext_names[8 ][256 ]; -}; static uint8_t pagebuf[PAGE_SIZE * 2] __attribute__((aligned(PAGE_SIZE * 2)));static void test_specs (void )@@ -91,7 +72,7 @@ static void test_3_2_2(void)/* EBCDIC for "KVM/" */ const uint8_t cpi_kvm[] = {0xd2 ,0xe5 ,0xd4 ,0x61 };const char vm_name_ext[] ="kvm-unit-test" ; -struct stsi_322 *data = (void *)pagebuf; +struct sysinfo_3_2_2 *data = (void *)pagebuf;report_prefix_push ("3.2.2" );
PATCH v4 3/4 s390x: topology: Check the Perform Topology Function
In reply to Pierre MorelWe check the PTF instruction.
- We do not expect to support vertical polarization.
- We do not expect the Modified Topology Change Report to be pending or not at the moment the first PTF instruction with PTF_CHECK function code is done as some code already did run a polarization change may have occur.
--- s390x/Makefile | 1 + s390x/topology.c | 115 ++++++++++++++++++++++++++++++++++++++++++++ s390x/unittests.cfg | 3 ++ 3 files changed, 119 insertions(+) create mode 100644 s390x/topology.c
s390x/Makefile +1 -0
@@ -26,6 +26,7 @@ tests += $(TEST_DIR)/edat.elf tests += $(TEST_DIR)/mvpg-sie.elf tests += $(TEST_DIR)/spec_ex-sie.elf tests += $(TEST_DIR)/firq.elf +tests += $(TEST_DIR)/topology.elf pv-tests += $(TEST_DIR)/pv-diags.elf
s390x/topology.c new file +115 -0
115 lines not on this page · raw message
s390x/unittests.cfg +3 -0
@@ -122,3 +122,6 @@ extra_params = -smp 1,maxcpus=3 -cpu qemu -device qemu-s390x-cpu,core-id=1 -devi file = firq.elf timeout = 20 extra_params = -smp 1,maxcpus=3 -cpu qemu -device qemu-s390x-cpu,core-id=2 -device qemu-s390x-cpu,core-id=1 + +[topology] +file = topology.elf
Signature · 1 line
2.27.0
Re: [kvm-unit-tests PATCH v4 3/4] s390x: topology: Check the Perform Topology Function
Quoted 1 line · Pierre Morel
We check the PTF instruction.
You could test some very basic things as well:
- you get a privileged pgm int in problem state,
- reserved bits in first operand cause specification pgm int,
- reserved FC values result in a specification pgm int,
- second operand is ignored.
Quoted 4 lines
- We do not expect to support vertical polarization.
- We do not expect the Modified Topology Change Report to be
[...]
Forgive me if I'm missing something, but why _Modified_ Topology Change Report?
Quoted 5 lines
s390x/topology.c new file +0
-0
[...]
s390x/topology.c line 37
Quoted 10 lines
s390x/topology.c new file +10
-0+static int ptf (unsigned long fc,unsigned long *rc) +{ + int cc; + + asm volatile( + " .insn rre,0xb9a20000,%1,0\n" + " ipm %0\n" + " srl %0,28\n" + : "=d" (cc), "+d" (fc) + : "d" (fc)
Why list fc here again?
Re: [kvm-unit-tests PATCH v4 3/4] s390x: topology: Check the Perform Topology Function
Quoted 9 lines · Nico Boehr
Quoted 1 line · Pierre Morel
We check the PTF instruction.
You could test some very basic things as well:
- you get a privileged pgm int in problem state,
- reserved bits in first operand cause specification pgm int,
- reserved FC values result in a specification pgm int,
- second operand is ignored.
right, I will add these, I was more focused on the functionalities
Quoted 18 lines
Quoted 5 lines
- We do not expect to support vertical polarization.
- We do not expect the Modified Topology Change Report to be
[...]
Forgive me if I'm missing something, but why _Modified_ Topology Change Report?
Quoted 5 lines
s390x/topology.c new file +0
-0[...]
Quoted 14 lines
s390x/topology.c line 37
Quoted 10 lines
s390x/topology.c new file +10
-0+static int ptf (unsigned long fc,unsigned long *rc) +{ + int cc; + + asm volatile( + " .insn rre,0xb9a20000,%1,0\n" + " ipm %0\n" + " srl %0,28\n" + : "=d" (cc), "+d" (fc) + : "d" (fc)Why list fc here again?
No reason, I suppress it.
Thanks for the review
pierre
Signature · 2 lines
Pierre Morel IBM Lab Boeblingen
Re: [kvm-unit-tests PATCH v4 3/4] s390x: topology: Check the Perform Topology Function
In reply to Nico BoehrQuoted 11 lines · Nico Boehr
Quoted 1 line · Pierre Morel
We check the PTF instruction.
You could test some very basic things as well:
- you get a privileged pgm int in problem state,
- reserved bits in first operand cause specification pgm int,
- reserved FC values result in a specification pgm int,
- second operand is ignored.Quoted 1 line
Quoted 7 lines
Quoted 3 lines
- We do not expect to support vertical polarization.
- We do not expect the Modified Topology Change Report to be
[...]
Forgive me if I'm missing something, but why _Modified_ Topology Change Report?
This does only exist in my mind the real name is indeed only Topology change report.
Quoted 23 lines
Quoted 6 lines
s390x/topology.c new file +0
-0[...]
s390x/topology.c line 37
Quoted 10 lines
s390x/topology.c new file +10
-0+static int ptf (unsigned long fc,unsigned long *rc) +{ + int cc; + + asm volatile( + " .insn rre,0xb9a20000,%1,0\n" + " ipm %0\n" + " srl %0,28\n" + : "=d" (cc), "+d" (fc) + : "d" (fc)Why list fc here again?
Signature · 2 lines
Pierre Morel IBM Lab Boeblingen
Re: [kvm-unit-tests PATCH v4 3/4] s390x: topology: Check the Perform Topology Function
In reply to Nico BoehrQuoted 9 lines · Nico Boehr
Quoted 1 line · Pierre Morel
We check the PTF instruction.
You could test some very basic things as well:
- you get a privileged pgm int in problem state,
- reserved bits in first operand cause specification pgm int,
- reserved FC values result in a specification pgm int,
- second operand is ignored.
Which second operand?
Quoted 32 lines
Quoted 5 lines
- We do not expect to support vertical polarization.
- We do not expect the Modified Topology Change Report to be
[...]
Forgive me if I'm missing something, but why _Modified_ Topology Change Report?
Quoted 5 lines
s390x/topology.c new file +0
-0[...]
s390x/topology.c line 37
Quoted 10 lines
s390x/topology.c new file +10
-0+static int ptf (unsigned long fc,unsigned long *rc) +{ + int cc; + + asm volatile( + " .insn rre,0xb9a20000,%1,0\n" + " ipm %0\n" + " srl %0,28\n" + : "=d" (cc), "+d" (fc) + : "d" (fc)Why list fc here again?
Signature · 2 lines
Pierre Morel IBM Lab Boeblingen
Re: [kvm-unit-tests PATCH v4 3/4] s390x: topology: Check the Perform Topology Function
Quoted 6 lines · Pierre Morel
Quoted 3 lines · Nico Boehr
Quoted 1 line · Pierre Morel
We check the PTF instruction.
Quoted 8 lines
Quoted 6 lines
You could test some very basic things as well:
- you get a privileged pgm int in problem state,
- reserved bits in first operand cause specification pgm int,
- reserved FC values result in a specification pgm int,
- second operand is ignored.Which second operand?
Sorry got it
Quoted 34 lines
Quoted 33 lines
Quoted 6 lines
- We do not expect to support vertical polarization.
- We do not expect the Modified Topology Change Report to be
[...]
Forgive me if I'm missing something, but why _Modified_ Topology Change Report?
Quoted 5 lines
s390x/topology.c new file +0
-0[...]
s390x/topology.c line 37
Quoted 10 lines
s390x/topology.c new file +10
-0+static int ptf (unsigned long fc,unsigned long *rc) +{ + int cc; + + asm volatile( + " .insn rre,0xb9a20000,%1,0\n" + " ipm %0\n" + " srl %0,28\n" + : "=d" (cc), "+d" (fc) + : "d" (fc)Why list fc here again?
Signature · 2 lines
Pierre Morel IBM Lab Boeblingen
Re: [kvm-unit-tests PATCH v4 3/4] s390x: topology: Check the Perform Topology Function
Quoted 11 lines · Pierre Morel
Quoted 8 lines · Pierre Morel
Quoted 5 lines · Nico Boehr
Quoted 1 line · Pierre Morel
We check the PTF instruction.
You could test some very basic things as well:
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
- you get a privileged pgm int in problem state,
- reserved bits in first operand cause specification pgm int,
- reserved FC values result in a specification pgm int,
- second operand is ignored.Which second operand?
Sorry got it
I was a little fast in my answer, twice.
If the second operand is ignored, how would you like to check something like that?
We can check that the result of the instruction is identical for the known effects the user can check what ever we put in there but how can we know if it is really ignored?
Quoted 35 lines
Quoted 34 lines
Quoted 33 lines
Quoted 6 lines
- We do not expect to support vertical polarization.
- We do not expect the Modified Topology Change Report to be
[...]
Forgive me if I'm missing something, but why _Modified_ Topology Change Report?
Quoted 5 lines
s390x/topology.c new file +0
-0[...]
s390x/topology.c line 37
Quoted 10 lines
s390x/topology.c new file +10
-0+static int ptf (unsigned long fc,unsigned long *rc) +{ + int cc; + + asm volatile( + " .insn rre,0xb9a20000,%1,0\n" + " ipm %0\n" + " srl %0,28\n" + : "=d" (cc), "+d" (fc) + : "d" (fc)Why list fc here again?
Signature · 2 lines
Pierre Morel IBM Lab Boeblingen
Re: [kvm-unit-tests PATCH v4 3/4] s390x: topology: Check the Perform Topology Function
Quoted 6 lines · Pierre Morel
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
- second operand is ignored.
Which second operand?
Sorry got it
Quoted 8 lines
I was a little fast in my answer, twice.
If the second operand is ignored, how would you like to check something
like that?
We can check that the result of the instruction is identical for the known effects the user can check what ever we put in there but how can
we know if it is really ignored?
Yes, there is no 100% guarantee. If you think there is no value or it's too difficult to test for the value it adds, it is fine for me if you leave it out.
Your suggestion sounds fine, though.
PATCH v4 4/4 s390x: topology: Checking Configuration Topology Information
In reply to Pierre MorelSTSI with function code 15 is used to store the CPU configuration topology.
We check :
- if the topology stored is coherent between the QEMU -smp parameters and kernel parameters.
- the number of CPUs
- the maximum number of CPUs
- the number of containers of each levels for every STSI(15.1.x) instruction allowed by the machine.
--- lib/s390x/stsi.h | 44 +++++++++ s390x/topology.c | 231 ++++++++++++++++++++++++++++++++++++++++++++ s390x/unittests.cfg | 1 + 3 files changed, 276 insertions(+)
lib/s390x/stsi.h +44 -0
@@ -29,4 +29,48 @@ struct sysinfo_3_2_2 {uint8_t ext_names[8 ][256 ]; }; +struct topology_core { +uint8_t nl; +uint8_t reserved1[3 ]; +uint8_t reserved4:5 ; +uint8_t d:1 ; +uint8_t pp:2 ; +uint8_t type; +uint16_t origin; +uint64_t mask; +}; + +struct topology_container { +uint8_t nl; +uint8_t reserved[6 ]; +uint8_t id; +}; + +union topology_entry { +uint8_t nl; +struct topology_core cpu; +struct topology_container container; +}; + +#define CPU_TOPOLOGY_MAX_LEVEL 6 +struct sysinfo_15_1_x { +uint8_t reserved0[2 ]; +uint16_t length; +uint8_t mag[CPU_TOPOLOGY_MAX_LEVEL ]; +uint8_t reserved0a; +uint8_t mnest; +uint8_t reserved0c[4 ]; +union topology_entry tle[0 ]; +}; + +static inline int cpus_in_tle_mask (uint64_t val) +{ +int i, n; + +for (i =0 , n =0 ; i <64 ; i++, val >>=1 ) +if (val &0x01 ) + n++; +return n; +} +#endif /* _S390X_STSI_H_ */
s390x/topology.c +231 -0
260 lines not on this page · raw message
s390x/unittests.cfg +1 -0
@@ -125,3 +125,4 @@ extra_params = -smp 1,maxcpus=3 -cpu qemu -device qemu-s390x-cpu,core-id=2 -devi [topology] file = topology.elf +extra_params=-smp 5,drawers=2,books=3,sockets=4,cores=4,maxcpus=16 -append "-d 2 -b 3 -s 4 -c 4"
Signature · 1 line
2.27.0