Skip to contentSkip to conversation

lib: s390x: Refactor and rename vm.[ch]

PATCH In review Claudio Imbrenda 2 participants 9 messages Mar 31, 2022 – Apr 1, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover lib: s390x: Refactor and rename vm.[ch]

Refactor and rename vm.[ch] to hardware.[ch]

* Remove some uneeded #includes for vm.h
* Rename vm.[ch] to hardware.[ch]
* Consolidate all detection functions into detect_host, which returns what host system the test is running on
* Completely remove obsolete z/VM 6.x check from skey.c
* Rename vm_is_* functions to host_is_*, which are then just wrappers around detect_host
* Move machine type macros from arch_def.h to hardware.h
* Add machine_is_* functions
* Refactor and rename get_machine_id to be a simple wrapper for stidp
* Add back get_machine_id using the stidp wrapper

v1->v2
* new patch to completely remove obsolete z/VM 6.x check instead of moving it into hardware.h
* do not add macros and functions for all known machine types, z15 is enough for now

Claudio Imbrenda (5):
s390x: remove spurious includes
s390x: skey: remove check for old z/VM version
lib: s390: rename and refactor vm.[ch]
lib: s390x: functions for machine models
lib: s390x: stidp wrapper and move get_machine_id

 s390x/Makefile           |  2 +-
 lib/s390x/asm/arch_def.h |  7 +--
 lib/s390x/hardware.h     | 55 ++++++++++++++++++++++++
 lib/s390x/vm.h           | 15 -------
 lib/s390x/hardware.c     | 69 ++++++++++++++++++++++++++++++
 lib/s390x/vm.c           | 92 ----------------------------------------
 s390x/cpumodel.c         |  4 +-
 s390x/mvpg-sie.c         |  1 -
 s390x/mvpg.c             |  4 +-
 s390x/pv-diags.c         |  1 -
 s390x/skey.c             | 37 ++--------------
 s390x/spec_ex-sie.c      |  1 -
 s390x/uv-host.c          |  4 +-
 13 files changed, 136 insertions(+), 156 deletions(-)
 create mode 100644 lib/s390x/hardware.h
 delete mode 100644 lib/s390x/vm.h
 create mode 100644 lib/s390x/hardware.c
 delete mode 100644 lib/s390x/vm.c
Signature · 1 line
2.34.1
#1 lore raw

PATCH v2 1/5 s390x: remove spurious includes

Remove unused includes of vm.h

---
 s390x/mvpg-sie.c    | 1 -
 s390x/pv-diags.c    | 1 -
 s390x/spec_ex-sie.c | 1 -
 3 files changed, 3 deletions(-)
s390x/mvpg-sie.c +0 -1
index 8ae9a52a..46a2edb6 100644
@@ -16,7 +16,6 @@
 #include <asm/facility.h>
 #include <asm/mem.h>
 #include <alloc_page.h>
-#include <vm.h>
 #include <sclp.h>
 #include <sie.h>
 #include <snippet.h>
s390x/pv-diags.c +0 -1
index 110547ad..6899b859 100644
@@ -19,7 +19,6 @@
 #include <asm/sigp.h>
 #include <smp.h>
 #include <alloc_page.h>
-#include <vm.h>
 #include <vmalloc.h>
 #include <sclp.h>
 #include <snippet.h>
s390x/spec_ex-sie.c +0 -1
index 5dea4115..d8e25e75 100644
@@ -11,7 +11,6 @@
 #include <asm/page.h>
 #include <asm/arch_def.h>
 #include <alloc_page.h>
-#include <vm.h>
 #include <sie.h>
 #include <snippet.h>
 
Signature · 1 line
2.34.1
#2 lore raw

PATCH v2 2/5 s390x: skey: remove check for old z/VM version

In reply to Claudio Imbrenda

Remove the check for z/VM 6.x, since it is not needed anymore.

---
 s390x/skey.c | 37 ++++---------------------------------
 1 file changed, 4 insertions(+), 33 deletions(-)
s390x/skey.c +4 -33
index 58a55436..edad53e9 100644
@@ -65,33 +65,9 @@ static void test_set(void)
 	       "set key test");
 }
 
-/* Returns true if we are running under z/VM 6.x */
-static bool check_for_zvm6(void)
-{
-	int dcbt;	/* Descriptor block count */
-	int nr;
-	static const unsigned char zvm6[] = {
-		/* This is "z/VM    6" in EBCDIC */
-		0xa9, 0x61, 0xe5, 0xd4, 0x40, 0x40, 0x40, 0x40, 0xf6
-	};
-
-	if (stsi(pagebuf, 3, 2, 2))
-		return false;
-
-	dcbt = pagebuf[31] & 0xf;
-
-	for (nr = 0; nr < dcbt; nr++) {
-		if (!memcmp(&pagebuf[32 + nr * 64 + 24], zvm6, sizeof(zvm6)))
-			return true;
-	}
-
-	return false;
-}
-
 static void test_priv(void)
 {
 	union skey skey;
-	bool is_zvm6 = check_for_zvm6();
 
 	memset(pagebuf, 0, PAGE_SIZE * 2);
 	report_prefix_push("privileged");
@@ -106,15 +82,10 @@ static void test_priv(void)
 	report(skey.str.acc != 3, "skey did not change on exception");
 
 	report_prefix_push("iske");
-	if (is_zvm6) {
-		/* There is a known bug with z/VM 6, so skip the test there */
-		report_skip("not working on z/VM 6");
-	} else {
-		expect_pgm_int();
-		enter_pstate();
-		get_storage_key(pagebuf);
-		check_pgm_int_code(PGM_INT_CODE_PRIVILEGED_OPERATION);
-	}
+	expect_pgm_int();
+	enter_pstate();
+	get_storage_key(pagebuf);
+	check_pgm_int_code(PGM_INT_CODE_PRIVILEGED_OPERATION);
 	report_prefix_pop();
 
 	report_prefix_pop();
Signature · 1 line
2.34.1
Reviewed-by on v2 2/5
#3 lore raw

Re: [kvm-unit-tests PATCH v2 2/5] s390x: skey: remove check for old z/VM version

Quoted 3 lines · Claudio Imbrenda

Remove the check for z/VM 6.x, since it is not needed anymore.

Thanks for taking care of this.

Quoted 62 lines
---
  s390x/skey.c | 37 ++++---------------------------------
  1 file changed, 4 insertions(+), 33 deletions(-)
s390x/skey.c +4 -33
index 58a55436..edad53e9 100644
@@ -65,33 +65,9 @@ static void test_set(void)
  	       "set key test");
  }
 
-/* Returns true if we are running under z/VM 6.x */
-static bool check_for_zvm6(void)
-{
-	int dcbt;	/* Descriptor block count */
-	int nr;
-	static const unsigned char zvm6[] = {
-		/* This is "z/VM    6" in EBCDIC */
-		0xa9, 0x61, 0xe5, 0xd4, 0x40, 0x40, 0x40, 0x40, 0xf6
-	};
-
-	if (stsi(pagebuf, 3, 2, 2))
-		return false;
-
-	dcbt = pagebuf[31] & 0xf;
-
-	for (nr = 0; nr < dcbt; nr++) {
-		if (!memcmp(&pagebuf[32 + nr * 64 + 24], zvm6, sizeof(zvm6)))
-			return true;
-	}
-
-	return false;
-}
-
  static void test_priv(void)
  {
  	union skey skey;
-	bool is_zvm6 = check_for_zvm6();
 
  	memset(pagebuf, 0, PAGE_SIZE * 2);
  	report_prefix_push("privileged");
@@ -106,15 +82,10 @@ static void test_priv(void)
  	report(skey.str.acc != 3, "skey did not change on exception");
 
  	report_prefix_push("iske");
-	if (is_zvm6) {
-		/* There is a known bug with z/VM 6, so skip the test there */
-		report_skip("not working on z/VM 6");
-	} else {
-		expect_pgm_int();
-		enter_pstate();
-		get_storage_key(pagebuf);
-		check_pgm_int_code(PGM_INT_CODE_PRIVILEGED_OPERATION);
-	}
+	expect_pgm_int();
+	enter_pstate();
+	get_storage_key(pagebuf);
+	check_pgm_int_code(PGM_INT_CODE_PRIVILEGED_OPERATION);
  	report_prefix_pop();
 
  	report_prefix_pop();
#4 lore raw

PATCH v2 3/5 lib: s390: rename and refactor vm.[ch]

In reply to Claudio Imbrenda

Refactor and rename vm.[ch] to hardware.[ch]

* Rename vm.[ch] to hardware.[ch]
* Consolidate all detection functions into detect_host, which returns what host system the test is running on
* Rename vm_is_* functions to host_is_*, which are then just wrappers around detect_host

---
 s390x/Makefile       |  2 +-
 lib/s390x/hardware.h | 40 +++++++++++++++++++
 lib/s390x/vm.h       | 15 --------
 lib/s390x/hardware.c | 69 +++++++++++++++++++++++++++++++++
 lib/s390x/vm.c       | 92 --------------------------------------------
 s390x/cpumodel.c     |  4 +-
 s390x/mvpg.c         |  4 +-
 7 files changed, 114 insertions(+), 112 deletions(-)
 create mode 100644 lib/s390x/hardware.h
 delete mode 100644 lib/s390x/vm.h
 create mode 100644 lib/s390x/hardware.c
 delete mode 100644 lib/s390x/vm.c
s390x/Makefile +1 -1
index 53b0fe04..9d3a1fd7 100644
@@ -78,7 +78,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
+cflatobjs += lib/s390x/hardware.o
 cflatobjs += lib/s390x/css_dump.o
 cflatobjs += lib/s390x/css_lib.o
 cflatobjs += lib/s390x/malloc_io.o
lib/s390x/hardware.h new file +40 -0
new file mode 100644
index 00000000..e5910ea5
@@ -0,0 +1,40 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Functions to retrieve information about the host system.
+ *
+ * Copyright (c) 2020 Red Hat Inc
+ * Copyright 2022 IBM Corp.
+ *
+ * Authors:
+ *  Claudio Imbrenda <[email protected]>
+ */
+
+#ifndef _S390X_HARDWARE_H_
+#define _S390X_HARDWARE_H_
+#include <asm/arch_def.h>
+
+enum s390_host {
+	HOST_IS_UNKNOWN,
+	HOST_IS_LPAR,
+	HOST_IS_KVM,
+	HOST_IS_TCG
+};
+
+enum s390_host detect_host(void);
+
+static inline bool host_is_tcg(void)
+{
+	return detect_host() == HOST_IS_TCG;
+}
+
+static inline bool host_is_kvm(void)
+{
+	return detect_host() == HOST_IS_KVM;
+}
+
+static inline bool host_is_lpar(void)
+{
+	return detect_host() == HOST_IS_LPAR;
+}
+
+#endif  /* _S390X_HARDWARE_H_ */
lib/s390x/vm.h deleted +0 -15
deleted file mode 100644
index 4456b48c..00000000
@@ -1,15 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-or-later */
-/*
- * Functions to retrieve VM-specific information
- *
- * Copyright (c) 2020 Red Hat Inc
- */
-
-#ifndef _S390X_VM_H_
-#define _S390X_VM_H_
-
-bool vm_is_tcg(void);
-bool vm_is_kvm(void);
-bool vm_is_lpar(void);
-
-#endif  /* _S390X_VM_H_ */
lib/s390x/hardware.c new file +69 -0

69 lines not on this page · raw message

lib/s390x/vm.c deleted +0 -92

92 lines not on this page · raw message

s390x/cpumodel.c +2 -2
index 23ccf842..5c0b73e0 100644
@@ -10,7 +10,7 @@
  */
 
 #include <asm/facility.h>
-#include <vm.h>
+#include <hardware.h>
 #include <sclp.h>
 #include <uv.h>
 #include <asm/uv.h>
@@ -118,7 +118,7 @@ int main(void)
 	for (i = 0; i < ARRAY_SIZE(dep); i++) {
 		report_prefix_pushf("%d implies %d", dep[i].facility, dep[i].implied);
 		if (test_facility(dep[i].facility)) {
-			report_xfail(dep[i].expected_tcg_fail && vm_is_tcg(),
+			report_xfail(dep[i].expected_tcg_fail && host_is_tcg(),
 				     test_facility(dep[i].implied),
 				     "implication not correct");
 		} else {
s390x/mvpg.c +2 -2
index 2b7c6cc9..62f0fc5a 100644
@@ -20,7 +20,7 @@
 #include <smp.h>
 #include <alloc_page.h>
 #include <bitops.h>
-#include <vm.h>
+#include <hardware.h>
 
 /* Used to build the appropriate test values for register 0 */
 #define KFC(x) ((x) << 10)
@@ -251,7 +251,7 @@ static void test_mmu_prot(void)
 	fresh += PAGE_SIZE;
 
 	/* Known issue in TCG: CCO flag is not honoured */
-	if (vm_is_tcg()) {
+	if (host_is_tcg()) {
 		report_prefix_push("TCG");
 		report_skip("destination invalid");
 		report_skip("source invalid");
Signature · 1 line
2.34.1
Reviewed-by on v2 3/5
#5 lore raw

Re: [kvm-unit-tests PATCH v2 3/5] lib: s390: rename and refactor vm.[ch]

Quoted 9 lines · Claudio Imbrenda

Refactor and rename vm.[ch] to hardware.[ch]

* Rename vm.[ch] to hardware.[ch]
* Consolidate all detection functions into detect_host, which returns what host system the test is running on
* Rename vm_is_* functions to host_is_*, which are then just wrappers around detect_host

Nice

Quoted 311 lines
---
  s390x/Makefile       |  2 +-
  lib/s390x/hardware.h | 40 +++++++++++++++++++
  lib/s390x/vm.h       | 15 --------
  lib/s390x/hardware.c | 69 +++++++++++++++++++++++++++++++++
  lib/s390x/vm.c       | 92 --------------------------------------------
  s390x/cpumodel.c     |  4 +-
  s390x/mvpg.c         |  4 +-
  7 files changed, 114 insertions(+), 112 deletions(-)

create mode 100644 lib/s390x/hardware.h
delete mode 100644 lib/s390x/vm.h
create mode 100644 lib/s390x/hardware.c
delete mode 100644 lib/s390x/vm.c

s390x/Makefile +1 -1
index 53b0fe04..9d3a1fd7 100644
@@ -78,7 +78,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
+cflatobjs += lib/s390x/hardware.o
  cflatobjs += lib/s390x/css_dump.o
  cflatobjs += lib/s390x/css_lib.o
  cflatobjs += lib/s390x/malloc_io.o
lib/s390x/hardware.h new file +40 -0
new file mode 100644
index 00000000..e5910ea5
@@ -0,0 +1,40 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Functions to retrieve information about the host system.
+ *
+ * Copyright (c) 2020 Red Hat Inc
+ * Copyright 2022 IBM Corp.
+ *
+ * Authors:
+ *  Claudio Imbrenda <[email protected]>
+ */
+
+#ifndef _S390X_HARDWARE_H_
+#define _S390X_HARDWARE_H_
+#include <asm/arch_def.h>
+
+enum s390_host {
+	HOST_IS_UNKNOWN,
+	HOST_IS_LPAR,
+	HOST_IS_KVM,
+	HOST_IS_TCG
+};
+
+enum s390_host detect_host(void);
+
+static inline bool host_is_tcg(void)
+{
+	return detect_host() == HOST_IS_TCG;
+}
+
+static inline bool host_is_kvm(void)
+{
+	return detect_host() == HOST_IS_KVM;
+}
+
+static inline bool host_is_lpar(void)
+{
+	return detect_host() == HOST_IS_LPAR;
+}
+
+#endif  /* _S390X_HARDWARE_H_ */
lib/s390x/vm.h deleted +0 -15
deleted file mode 100644
index 4456b48c..00000000
@@ -1,15 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-or-later */
-/*
- * Functions to retrieve VM-specific information
- *
- * Copyright (c) 2020 Red Hat Inc
- */
-
-#ifndef _S390X_VM_H_
-#define _S390X_VM_H_
-
-bool vm_is_tcg(void);
-bool vm_is_kvm(void);
-bool vm_is_lpar(void);
-
-#endif  /* _S390X_VM_H_ */
lib/s390x/hardware.c new file +69 -0
new file mode 100644
index 00000000..2bcf9c4c
@@ -0,0 +1,69 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Functions to retrieve information about the host system.
+ *
+ * Copyright (c) 2020 Red Hat Inc
+ * Copyright 2022 IBM Corp.
+ *
+ * Authors:
+ *  Thomas Huth <[email protected]>
+ *  Claudio Imbrenda <[email protected]>
+ */
+
+#include <libcflat.h>
+#include <alloc_page.h>
+#include <asm/arch_def.h>
+#include "hardware.h"
+#include "stsi.h"
+
+/* The string "QEMU" in EBCDIC */
+static const uint8_t qemu_ebcdic[] = { 0xd8, 0xc5, 0xd4, 0xe4 };
+/* The string "KVM/" in EBCDIC */
+static const uint8_t kvm_ebcdic[] = { 0xd2, 0xe5, 0xd4, 0x61 };
+
+static enum s390_host do_detect_host(void *buf)
+{
+	struct sysinfo_3_2_2 *stsi_322 = buf;
+
+	if (stsi_get_fc() == 2)
+		return HOST_IS_LPAR;
+
+	if (stsi_get_fc() != 3)
+		return HOST_IS_UNKNOWN;
+
+	if (!stsi(buf, 1, 1, 1)) {
+		/*
+		 * If the manufacturer string is "QEMU" in EBCDIC, then we
+		 * are on TCG (otherwise the string is "IBM" in EBCDIC)
+		 */
+		if (!memcmp((char *)buf + 32, qemu_ebcdic, sizeof(qemu_ebcdic)))
+			return HOST_IS_TCG;
+	}
+
+	if (!stsi(buf, 3, 2, 2)) {
+		/*
+		 * If the manufacturer string is "KVM/" in EBCDIC, then we
+		 * are on KVM.
+		 */
+		if (!memcmp(&stsi_322->vm[0].cpi, kvm_ebcdic, sizeof(kvm_ebcdic)))
+			return HOST_IS_KVM;
+	}
+
+	return HOST_IS_UNKNOWN;
+}
+
+enum s390_host detect_host(void)
+{
+	static enum s390_host host = HOST_IS_UNKNOWN;
+	static bool initialized = false;
+	void *buf;
+
+	if (initialized)
+		return host;
+
+	buf = alloc_page();
+	host = do_detect_host(buf);
+	free_page(buf);
+	initialized = true;
+	return host;
+}
lib/s390x/vm.c deleted +0 -92
deleted file mode 100644
index 33fb1c45..00000000
@@ -1,92 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-or-later */
-/*
- * Functions to retrieve VM-specific information
- *
- * Copyright (c) 2020 Red Hat Inc
- *
- * Authors:
- *  Thomas Huth <[email protected]>
- */
-
-#include <libcflat.h>
-#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)
- */
-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;
-
-	if (stsi_get_fc() != 3) {
-		initialized = true;
-		return is_tcg;
-	}
-
-	buf = alloc_page();
-	assert(buf);
-
-	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;
-}
-
-/**
- * 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 (stsi_get_fc() != 3 || 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;
-}
-
-bool vm_is_lpar(void)
-{
-	return stsi_get_fc() == 2;
-}
-
s390x/cpumodel.c +2 -2
index 23ccf842..5c0b73e0 100644
@@ -10,7 +10,7 @@
   */
 
  #include <asm/facility.h>
-#include <vm.h>
+#include <hardware.h>
  #include <sclp.h>
  #include <uv.h>
  #include <asm/uv.h>
@@ -118,7 +118,7 @@ int main(void)
  	for (i = 0; i < ARRAY_SIZE(dep); i++) {
  		report_prefix_pushf("%d implies %d", dep[i].facility, dep[i].implied);
  		if (test_facility(dep[i].facility)) {
-			report_xfail(dep[i].expected_tcg_fail && vm_is_tcg(),
+			report_xfail(dep[i].expected_tcg_fail && host_is_tcg(),
  				     test_facility(dep[i].implied),
  				     "implication not correct");
  		} else {
s390x/mvpg.c +2 -2
index 2b7c6cc9..62f0fc5a 100644
@@ -20,7 +20,7 @@
  #include <smp.h>
  #include <alloc_page.h>
  #include <bitops.h>
-#include <vm.h>
+#include <hardware.h>
 
  /* Used to build the appropriate test values for register 0 */
  #define KFC(x) ((x) << 10)
@@ -251,7 +251,7 @@ static void test_mmu_prot(void)
  	fresh += PAGE_SIZE;
 
  	/* Known issue in TCG: CCO flag is not honoured */
-	if (vm_is_tcg()) {
+	if (host_is_tcg()) {
  		report_prefix_push("TCG");
  		report_skip("destination invalid");
  		report_skip("source invalid");
#6 lore raw

PATCH v2 4/5 lib: s390x: functions for machine models

In reply to Claudio Imbrenda

* move existing macros for machine models to hardware.h
* add machine_is_* functions

---
 lib/s390x/asm/arch_def.h |  3 ---
 lib/s390x/hardware.h     | 10 ++++++++++
 s390x/uv-host.c          |  4 ++--
 3 files changed, 12 insertions(+), 5 deletions(-)
lib/s390x/asm/arch_def.h +0 -3
index 40626d72..8d860ccf 100644
@@ -219,9 +219,6 @@ static inline unsigned short stap(void)
 	return cpu_address;
 }
 
-#define MACHINE_Z15A	0x8561
-#define MACHINE_Z15B	0x8562
-
 static inline uint16_t get_machine_id(void)
 {
 	uint64_t cpuid;
lib/s390x/hardware.h +10 -0
index e5910ea5..af20be18 100644
@@ -13,6 +13,9 @@
 #define _S390X_HARDWARE_H_
 #include <asm/arch_def.h>
 
+#define MACHINE_Z15	0x8561
+#define MACHINE_Z15T02	0x8562
+
 enum s390_host {
 	HOST_IS_UNKNOWN,
 	HOST_IS_LPAR,
@@ -37,4 +40,11 @@ static inline bool host_is_lpar(void)
 	return detect_host() == HOST_IS_LPAR;
 }
 
+static inline bool machine_is_z15(void)
+{
+	uint16_t machine = get_machine_id();
+
+	return machine == MACHINE_Z15 || machine == MACHINE_Z15T02;
+}
+
 #endif  /* _S390X_HARDWARE_H_ */
s390x/uv-host.c +2 -2
index de2e4850..d3018e3c 100644
@@ -9,6 +9,7 @@
  */
 
 #include <libcflat.h>
+#include <hardware.h>
 #include <alloc.h>
 #include <vmalloc.h>
 #include <sclp.h>
@@ -111,7 +112,6 @@ static void test_config_destroy(void)
 static void test_cpu_destroy(void)
 {
 	int rc;
-	uint16_t machineid = get_machine_id();
 	struct uv_cb_nodata uvcb = {
 		.header.len = sizeof(uvcb),
 		.header.cmd = UVC_CMD_DESTROY_SEC_CPU,
@@ -126,7 +126,7 @@ static void test_cpu_destroy(void)
 	       "hdr invalid length");
 	uvcb.header.len += 8;
 
-	if (machineid != MACHINE_Z15A && machineid != MACHINE_Z15B) {
+	if (!machine_is_z15()) {
 		uvcb.handle += 1;
 		rc = uv_call(0, (uint64_t)&uvcb);
 		report(rc == 1 && uvcb.header.rc == UVC_RC_INV_CHANDLE, "invalid handle");
Signature · 1 line
2.34.1
Reviewed-by on v2 4/5
#7 lore raw

Re: [kvm-unit-tests PATCH v2 4/5] lib: s390x: functions for machine models

Quoted 4 lines · Claudio Imbrenda

* move existing macros for machine models to hardware.h
* add machine_is_* functions

Quoted 75 lines
---
  lib/s390x/asm/arch_def.h |  3 ---
  lib/s390x/hardware.h     | 10 ++++++++++
  s390x/uv-host.c          |  4 ++--
  3 files changed, 12 insertions(+), 5 deletions(-)
lib/s390x/asm/arch_def.h +0 -3
index 40626d72..8d860ccf 100644
@@ -219,9 +219,6 @@ static inline unsigned short stap(void)
  	return cpu_address;
  }
 
-#define MACHINE_Z15A	0x8561
-#define MACHINE_Z15B	0x8562
-
  static inline uint16_t get_machine_id(void)
  {
  	uint64_t cpuid;
lib/s390x/hardware.h +10 -0
index e5910ea5..af20be18 100644
@@ -13,6 +13,9 @@
  #define _S390X_HARDWARE_H_
  #include <asm/arch_def.h>
 
+#define MACHINE_Z15	0x8561
+#define MACHINE_Z15T02	0x8562
+
  enum s390_host {
  	HOST_IS_UNKNOWN,
  	HOST_IS_LPAR,
@@ -37,4 +40,11 @@ static inline bool host_is_lpar(void)
  	return detect_host() == HOST_IS_LPAR;
  }
 
+static inline bool machine_is_z15(void)
+{
+	uint16_t machine = get_machine_id();
+
+	return machine == MACHINE_Z15 || machine == MACHINE_Z15T02;
+}
+
  #endif  /* _S390X_HARDWARE_H_ */
s390x/uv-host.c +2 -2
index de2e4850..d3018e3c 100644
@@ -9,6 +9,7 @@
   */
 
  #include <libcflat.h>
+#include <hardware.h>
  #include <alloc.h>
  #include <vmalloc.h>
  #include <sclp.h>
@@ -111,7 +112,6 @@ static void test_config_destroy(void)
  static void test_cpu_destroy(void)
  {
  	int rc;
-	uint16_t machineid = get_machine_id();
  	struct uv_cb_nodata uvcb = {
  		.header.len = sizeof(uvcb),
  		.header.cmd = UVC_CMD_DESTROY_SEC_CPU,
@@ -126,7 +126,7 @@ static void test_cpu_destroy(void)
  	       "hdr invalid length");
  	uvcb.header.len += 8;
 
-	if (machineid != MACHINE_Z15A && machineid != MACHINE_Z15B) {
+	if (!machine_is_z15()) {
  		uvcb.handle += 1;
  		rc = uv_call(0, (uint64_t)&uvcb);
  		report(rc == 1 && uvcb.header.rc == UVC_RC_INV_CHANDLE, "invalid handle");
#8 lore raw

PATCH v2 5/5 lib: s390x: stidp wrapper and move get_machine_id

In reply to Claudio Imbrenda

Refactor get_machine_id in arch_def.h into a simple wrapper around stidp, add back get_machine_id in hardware.h using the stidp wrapper.

---
 lib/s390x/asm/arch_def.h | 4 +---
 lib/s390x/hardware.h     | 5 +++++
 2 files changed, 6 insertions(+), 3 deletions(-)
lib/s390x/asm/arch_def.h +1 -3
index 8d860ccf..bab3c374 100644
@@ -219,13 +219,11 @@ static inline unsigned short stap(void)
 	return cpu_address;
 }
 
-static inline uint16_t get_machine_id(void)
+static inline uint64_t stidp(void)
 {
 	uint64_t cpuid;
 
 	asm volatile("stidp %0" : "=Q" (cpuid));
-	cpuid = cpuid >> 16;
-	cpuid &= 0xffff;
 
 	return cpuid;
 }
lib/s390x/hardware.h +5 -0
index af20be18..01eeb261 100644
@@ -25,6 +25,11 @@ enum s390_host {
 
 enum s390_host detect_host(void);
 
+static inline uint16_t get_machine_id(void)
+{
+	return stidp() >> 16;
+}
+
 static inline bool host_is_tcg(void)
 {
 	return detect_host() == HOST_IS_TCG;
Signature · 1 line
2.34.1