From: Nico Boehr <nrb@linux.ibm.com>
To: thuth@redhat.com, pbonzini@redhat.com, andrew.jones@linux.dev
Cc: kvm@vger.kernel.org, frankja@linux.ibm.com, imbrenda@linux.ibm.com
Subject: [kvm-unit-tests GIT PULL 25/26] s390x: add a test for SIE without MSO/MSL
Date: Fri, 10 Nov 2023 14:52:34 +0100 [thread overview]
Message-ID: <20231110135348.245156-26-nrb@linux.ibm.com> (raw)
In-Reply-To: <20231110135348.245156-1-nrb@linux.ibm.com>
Since we now have the ability to run guests without MSO/MSL, add a test
to make sure this doesn't break.
Reviewed-by: Thomas Huth <thuth@redhat.com>
Reviewed-by: Janosch Frank <frankja@linux.ibm.com>
Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
Link: https://lore.kernel.org/r/20231106163738.1116942-8-nrb@linux.ibm.com
[ nrb: __pa -> virt_to_pte_phys to fix incompatiblity with 2g align ]
Signed-off-by: Nico Boehr <nrb@linux.ibm.com>
---
s390x/Makefile | 2 +
s390x/snippets/c/sie-dat.h | 2 +
s390x/sie-dat.c | 114 +++++++++++++++++++++++++++++++++++++
s390x/snippets/c/sie-dat.c | 57 +++++++++++++++++++
s390x/unittests.cfg | 3 +
5 files changed, 178 insertions(+)
create mode 100644 s390x/snippets/c/sie-dat.h
create mode 100644 s390x/sie-dat.c
create mode 100644 s390x/snippets/c/sie-dat.c
diff --git a/s390x/Makefile b/s390x/Makefile
index 947a434..f79fd00 100644
--- a/s390x/Makefile
+++ b/s390x/Makefile
@@ -41,6 +41,7 @@ tests += $(TEST_DIR)/migration-sck.elf
tests += $(TEST_DIR)/exittime.elf
tests += $(TEST_DIR)/ex.elf
tests += $(TEST_DIR)/topology.elf
+tests += $(TEST_DIR)/sie-dat.elf
pv-tests += $(TEST_DIR)/pv-diags.elf
pv-tests += $(TEST_DIR)/pv-icptcode.elf
@@ -123,6 +124,7 @@ snippet_lib = $(snippet_asmlib) lib/auxinfo.o
# perquisites (=guests) for the snippet hosts.
# $(TEST_DIR)/<snippet-host>.elf: snippets = $(SNIPPET_DIR)/<c/asm>/<snippet>.gbin
$(TEST_DIR)/mvpg-sie.elf: snippets = $(SNIPPET_DIR)/c/mvpg-snippet.gbin
+$(TEST_DIR)/sie-dat.elf: snippets = $(SNIPPET_DIR)/c/sie-dat.gbin
$(TEST_DIR)/spec_ex-sie.elf: snippets = $(SNIPPET_DIR)/c/spec_ex.gbin
$(TEST_DIR)/pv-diags.elf: pv-snippets += $(SNIPPET_DIR)/asm/pv-diag-yield.gbin
diff --git a/s390x/snippets/c/sie-dat.h b/s390x/snippets/c/sie-dat.h
new file mode 100644
index 0000000..ed3f99f
--- /dev/null
+++ b/s390x/snippets/c/sie-dat.h
@@ -0,0 +1,2 @@
+#define GUEST_TEST_PAGE_COUNT 10
+#define GUEST_TOTAL_PAGE_COUNT 256
diff --git a/s390x/sie-dat.c b/s390x/sie-dat.c
new file mode 100644
index 0000000..f025777
--- /dev/null
+++ b/s390x/sie-dat.c
@@ -0,0 +1,114 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Tests SIE with paging.
+ *
+ * Copyright 2023 IBM Corp.
+ *
+ * Authors:
+ * Nico Boehr <nrb@linux.ibm.com>
+ */
+#include <libcflat.h>
+#include <vmalloc.h>
+#include <asm/pgtable.h>
+#include <mmu.h>
+#include <asm/page.h>
+#include <asm/interrupt.h>
+#include <alloc_page.h>
+#include <sclp.h>
+#include <sie.h>
+#include <snippet.h>
+#include "snippets/c/sie-dat.h"
+
+static struct vm vm;
+static pgd_t *guest_root;
+
+static void test_sie_dat(void)
+{
+ uint64_t test_page_gpa, test_page_hpa;
+ uint8_t *test_page_hva, expected_val;
+ bool contents_match;
+ uint8_t r1;
+
+ /* guest will tell us the guest physical address of the test buffer */
+ sie(&vm);
+ assert(vm.sblk->icptcode == ICPT_INST &&
+ (vm.sblk->ipa & 0xff00) == 0x8300 && vm.sblk->ipb == 0x9c0000);
+
+ r1 = (vm.sblk->ipa & 0xf0) >> 4;
+ test_page_gpa = vm.save_area.guest.grs[r1];
+ test_page_hpa = virt_to_pte_phys(guest_root, (void*)test_page_gpa);
+ test_page_hva = __va(test_page_hpa);
+ report_info("test buffer gpa=0x%lx hva=%p", test_page_gpa, test_page_hva);
+
+ /* guest will now write to the test buffer and we verify the contents */
+ sie(&vm);
+ assert(vm.sblk->icptcode == ICPT_INST &&
+ vm.sblk->ipa == 0x8300 && vm.sblk->ipb == 0x440000);
+
+ contents_match = true;
+ for (unsigned int i = 0; i < GUEST_TEST_PAGE_COUNT; i++) {
+ expected_val = 42 + i;
+ if (test_page_hva[i * PAGE_SIZE] != expected_val) {
+ report_fail("page %u mismatch actual_val=%x expected_val=%x",
+ i, test_page_hva[i], expected_val);
+ contents_match = false;
+ }
+ }
+ report(contents_match, "test buffer contents match");
+
+ /* the guest will now write to an unmapped address and we check that this causes a segment translation exception */
+ report_prefix_push("guest write to unmapped");
+ expect_pgm_int();
+ sie(&vm);
+ check_pgm_int_code(PGM_INT_CODE_SEGMENT_TRANSLATION);
+ report((lowcore.trans_exc_id & PAGE_MASK) == (GUEST_TOTAL_PAGE_COUNT * PAGE_SIZE), "TEID address match");
+ report_prefix_pop();
+}
+
+static void setup_guest(void)
+{
+ extern const char SNIPPET_NAME_START(c, sie_dat)[];
+ extern const char SNIPPET_NAME_END(c, sie_dat)[];
+ uint64_t guest_max_addr;
+ pgd_t *root;
+
+ setup_vm();
+ root = (pgd_t *)(stctg(1) & PAGE_MASK);
+
+ snippet_setup_guest(&vm, false);
+
+ /* allocate a region-1 table */
+ guest_root = pgd_alloc_one();
+
+ /* map guest memory 1:1 */
+ guest_max_addr = GUEST_TOTAL_PAGE_COUNT * PAGE_SIZE;
+ for (uint64_t i = 0; i < guest_max_addr; i += PAGE_SIZE)
+ install_page(guest_root, virt_to_pte_phys(root, vm.guest_mem + i), (void *)i);
+
+ /* set up storage limit supression - leave mso and msl intact they are ignored anyways */
+ vm.sblk->cpuflags |= CPUSTAT_SM;
+
+ /* set up the guest asce */
+ vm.save_area.guest.asce = __pa(guest_root) | ASCE_DT_REGION1 | REGION_TABLE_LENGTH;
+
+ snippet_init(&vm, SNIPPET_NAME_START(c, sie_dat),
+ SNIPPET_LEN(c, sie_dat), SNIPPET_UNPACK_OFF);
+}
+
+int main(void)
+{
+ report_prefix_push("sie-dat");
+ if (!sclp_facilities.has_sief2) {
+ report_skip("SIEF2 facility unavailable");
+ goto done;
+ }
+
+ setup_guest();
+ test_sie_dat();
+ sie_guest_destroy(&vm);
+
+done:
+ report_prefix_pop();
+ return report_summary();
+
+}
diff --git a/s390x/snippets/c/sie-dat.c b/s390x/snippets/c/sie-dat.c
new file mode 100644
index 0000000..ecfcb60
--- /dev/null
+++ b/s390x/snippets/c/sie-dat.c
@@ -0,0 +1,57 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Snippet used by the sie-dat.c test to verify paging without MSO/MSL
+ *
+ * Copyright (c) 2023 IBM Corp
+ *
+ * Authors:
+ * Nico Boehr <nrb@linux.ibm.com>
+ */
+#include <libcflat.h>
+#include <asm-generic/page.h>
+#include "sie-dat.h"
+
+static uint8_t test_pages[GUEST_TEST_PAGE_COUNT * PAGE_SIZE] __attribute__((__aligned__(PAGE_SIZE)));
+
+static inline void force_exit(void)
+{
+ asm volatile("diag 0,0,0x44\n"
+ :
+ :
+ : "memory"
+ );
+}
+
+static inline void force_exit_value(uint64_t val)
+{
+ asm volatile("diag %[val],0,0x9c\n"
+ :
+ : [val] "d"(val)
+ : "memory"
+ );
+}
+
+int main(void)
+{
+ uint8_t *invalid_ptr;
+
+ memset(test_pages, 0, sizeof(test_pages));
+ /* tell the host the page's physical address (we're running DAT off) */
+ force_exit_value((uint64_t)test_pages);
+
+ /* write some value to the page so the host can verify it */
+ for (size_t i = 0; i < GUEST_TEST_PAGE_COUNT; i++)
+ test_pages[i * PAGE_SIZE] = 42 + i;
+
+ /* indicate we've written all pages */
+ force_exit();
+
+ /* the first unmapped address */
+ invalid_ptr = (uint8_t *)(GUEST_TOTAL_PAGE_COUNT * PAGE_SIZE);
+ *invalid_ptr = 42;
+
+ /* indicate we've written the non-allowed page (should never get here) */
+ force_exit();
+
+ return 0;
+}
diff --git a/s390x/unittests.cfg b/s390x/unittests.cfg
index b08b0fb..f5024b6 100644
--- a/s390x/unittests.cfg
+++ b/s390x/unittests.cfg
@@ -380,3 +380,6 @@ extra_params = """-cpu max,ctop=on -smp cpus=1,drawers=2,books=2,sockets=2,cores
-device max-s390x-cpu,core-id=97,drawer-id=1,book-id=1,socket-id=1,entitlement=high,dedicated=true \
-device max-s390x-cpu,core-id=111,drawer-id=1,book-id=1,socket-id=1,entitlement=medium,dedicated=false \
"""
+
+[sie-dat]
+file = sie-dat.elf
--
2.41.0
next prev parent reply other threads:[~2023-11-10 13:54 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-10 13:52 [kvm-unit-tests GIT PULL 00/26] s390x: multiline unittests.cfg, sclp enhancements, topology fixes and improvements, sie without MSO/MSL, 2G guest alignment, bug fixes Nico Boehr
2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 01/26] s390x: spec_ex: load full register Nico Boehr
2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 02/26] s390x: run PV guests with confidential guest enabled Nico Boehr
2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 03/26] lib: s390x: hw: rework do_detect_host so we don't need allocation Nico Boehr
2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 04/26] lib: s390x: sclp: Add compat handling for HMC ASCII consoles Nico Boehr
2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 05/26] lib: s390x: sclp: Add line mode input handling Nico Boehr
2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 06/26] s390x: spec_ex-sie: refactor to use snippet API Nico Boehr
2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 07/26] s390x: sie: ensure guests are aligned to 2GB Nico Boehr
2023-11-22 11:06 ` Thomas Huth
2023-11-23 9:24 ` Nina Schoetterl-Glausch
2023-11-23 13:03 ` Thomas Huth
2023-11-23 14:16 ` Nico Boehr
2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 08/26] s390x: mvpg-sie: fix virtual-physical address confusion Nico Boehr
2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 09/26] s390x: topology: Introduce enums for polarization & cpu type Nico Boehr
2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 10/26] s390x: topology: Fix report message Nico Boehr
2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 11/26] s390x: topology: Use function parameter in stsi_get_sysib Nico Boehr
2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 12/26] s390x: topology: Fix parsing loop Nico Boehr
2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 13/26] s390x: topology: Make some report messages unique Nico Boehr
2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 14/26] s390x: topology: Refine stsi header test Nico Boehr
2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 15/26] s390x: topology: Rename topology_core to topology_cpu Nico Boehr
2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 16/26] s390x: topology: Rewrite topology list test Nico Boehr
2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 17/26] scripts: Implement multiline strings for extra_params Nico Boehr
2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 18/26] s390x: topology: Add complex topology test Nico Boehr
2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 19/26] lib: s390x: introduce bitfield for PSW mask Nico Boehr
2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 20/26] s390x: add function to set DAT mode for all interrupts Nico Boehr
2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 21/26] s390x: sie: switch to home space mode before entering SIE Nico Boehr
2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 22/26] s390x: lib: don't forward PSW when handling exception in SIE Nico Boehr
2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 23/26] s390x: lib: sie: don't reenter SIE on pgm int Nico Boehr
2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 24/26] s390x: add test source dir to include paths Nico Boehr
2023-11-10 13:52 ` Nico Boehr [this message]
2023-11-10 13:52 ` [kvm-unit-tests GIT PULL 26/26] lib: s390x: interrupt: remove TEID_ASCE defines Nico Boehr
2023-11-10 15:25 ` [kvm-unit-tests GIT PULL 00/26] s390x: multiline unittests.cfg, sclp enhancements, topology fixes and improvements, sie without MSO/MSL, 2G guest alignment, bug fixes Thomas Huth
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=20231110135348.245156-26-nrb@linux.ibm.com \
--to=nrb@linux.ibm.com \
--cc=andrew.jones@linux.dev \
--cc=frankja@linux.ibm.com \
--cc=imbrenda@linux.ibm.com \
--cc=kvm@vger.kernel.org \
--cc=pbonzini@redhat.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