From: Janosch Frank <frankja@linux.ibm.com>
To: kvm@vger.kernel.org
Cc: linux-s390@vger.kernel.org, imbrenda@linux.ibm.com,
david@redhat.com, thuth@redhat.com, cohuck@redhat.com,
nrb@linux.ibm.com
Subject: [kvm-unit-tests PATCH 1/5] lib: s390x: vm: Add kvm and lpar vm queries
Date: Fri, 14 Jan 2022 10:02:41 +0000 [thread overview]
Message-ID: <20220114100245.8643-2-frankja@linux.ibm.com> (raw)
In-Reply-To: <20220114100245.8643-1-frankja@linux.ibm.com>
This patch will likely (in parts) be replaced by Pierre's patch from
his topology test series.
Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
---
lib/s390x/vm.c | 39 +++++++++++++++++++++++++++++++++++++++
lib/s390x/vm.h | 23 +++++++++++++++++++++++
s390x/stsi.c | 21 +--------------------
3 files changed, 63 insertions(+), 20 deletions(-)
diff --git a/lib/s390x/vm.c b/lib/s390x/vm.c
index a5b92863..266a81c1 100644
--- a/lib/s390x/vm.c
+++ b/lib/s390x/vm.c
@@ -26,6 +26,11 @@ bool vm_is_tcg(void)
if (initialized)
return is_tcg;
+ if (stsi_get_fc() < 3) {
+ initialized = true;
+ return false;
+ }
+
buf = alloc_page();
if (!buf)
return false;
@@ -43,3 +48,37 @@ out:
free_page(buf);
return is_tcg;
}
+
+bool vm_is_kvm(void)
+{
+ const uint8_t cpi_kvm[] = { 0xd2, 0xe5, 0xd4, 0x61 };
+ struct stsi_322 *buf;
+ static bool initialized = false;
+ static bool is_kvm = false;
+
+ if (initialized)
+ return is_kvm;
+
+ if (stsi_get_fc() < 3) {
+ initialized = true;
+ return false;
+ }
+
+ buf = alloc_page();
+ if (!buf)
+ return false;
+
+ if (stsi(buf, 3, 2, 2))
+ goto out;
+
+ is_kvm = !(memcmp(&buf->vm[0].cpi, cpi_kvm, sizeof(cpi_kvm))) && !vm_is_tcg();
+ initialized = true;
+out:
+ free_page(buf);
+ return is_kvm;
+}
+
+bool vm_is_lpar(void)
+{
+ return stsi_get_fc() == 1;
+}
diff --git a/lib/s390x/vm.h b/lib/s390x/vm.h
index 7abba0cc..d4a82fc0 100644
--- a/lib/s390x/vm.h
+++ b/lib/s390x/vm.h
@@ -8,6 +8,29 @@
#ifndef _S390X_VM_H_
#define _S390X_VM_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];
+};
+
bool vm_is_tcg(void);
+bool vm_is_kvm(void);
+bool vm_is_lpar(void);
#endif /* _S390X_VM_H_ */
diff --git a/s390x/stsi.c b/s390x/stsi.c
index 391f8849..e66d07a1 100644
--- a/s390x/stsi.c
+++ b/s390x/stsi.c
@@ -13,27 +13,8 @@
#include <asm/asm-offsets.h>
#include <asm/interrupt.h>
#include <smp.h>
+#include <vm.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)
--
2.32.0
next prev parent reply other threads:[~2022-01-14 10:04 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-14 10:02 [kvm-unit-tests PATCH 0/5] s390x: Allocation and hosting environment detection fixes Janosch Frank
2022-01-14 10:02 ` Janosch Frank [this message]
2022-01-14 11:18 ` [kvm-unit-tests PATCH 1/5] lib: s390x: vm: Add kvm and lpar vm queries Claudio Imbrenda
2022-01-14 12:28 ` Janosch Frank
2022-01-14 12:55 ` Claudio Imbrenda
2022-01-14 13:27 ` Nico Boehr
2022-01-14 13:35 ` Janosch Frank
2022-01-14 13:43 ` Nico Boehr
2022-01-14 10:02 ` [kvm-unit-tests PATCH 2/5] s390x: css: Skip if we're not run by qemu Janosch Frank
2022-01-14 10:41 ` Claudio Imbrenda
2022-01-17 7:01 ` Thomas Huth
2022-01-14 10:02 ` [kvm-unit-tests PATCH 3/5] s390x: diag308: Only test subcode 2 under QEMU Janosch Frank
2022-01-14 10:39 ` Claudio Imbrenda
2022-01-17 7:04 ` Thomas Huth
2022-01-17 9:39 ` Janosch Frank
2022-01-14 10:02 ` [kvm-unit-tests PATCH 4/5] s390x: smp: Allocate memory in DMA31 space Janosch Frank
2022-01-14 11:18 ` Claudio Imbrenda
2022-01-14 12:50 ` Nico Boehr
2022-01-14 12:57 ` Claudio Imbrenda
2022-01-14 13:07 ` Janosch Frank
2022-01-14 13:01 ` Claudio Imbrenda
2022-01-14 13:13 ` Janosch Frank
2022-01-14 13:16 ` Claudio Imbrenda
2022-01-14 13:18 ` Janosch Frank
2022-01-14 13:19 ` Claudio Imbrenda
2022-01-14 10:02 ` [kvm-unit-tests PATCH 5/5] s390x: firq: Fix sclp buffer allocation Janosch Frank
2022-01-14 11:19 ` Claudio Imbrenda
2022-01-14 11:19 ` [kvm-unit-tests PATCH 0/5] s390x: Allocation and hosting environment detection fixes Claudio Imbrenda
2022-01-14 12:23 ` Janosch Frank
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220114100245.8643-2-frankja@linux.ibm.com \
--to=frankja@linux.ibm.com \
--cc=cohuck@redhat.com \
--cc=david@redhat.com \
--cc=imbrenda@linux.ibm.com \
--cc=kvm@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=nrb@linux.ibm.com \
--cc=thuth@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).