From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:23966 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729886AbhALNWA (ORCPT ); Tue, 12 Jan 2021 08:22:00 -0500 From: Janosch Frank Subject: [kvm-unit-tests PATCH v4 6/9] s390x: sie: Add first SIE test Date: Tue, 12 Jan 2021 08:20:51 -0500 Message-Id: <20210112132054.49756-7-frankja@linux.ibm.com> In-Reply-To: <20210112132054.49756-1-frankja@linux.ibm.com> References: <20210112132054.49756-1-frankja@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-ID: To: kvm@vger.kernel.org Cc: thuth@redhat.com, david@redhat.com, borntraeger@de.ibm.com, imbrenda@linux.ibm.com, cohuck@redhat.com, linux-s390@vger.kernel.org Let'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. Signed-off-by: Janosch Frank Reviewed-by: Thomas Huth Reviewed-by: Claudio Imbrenda Reviewed-by: Cornelia Huck --- s390x/Makefile | 1 + s390x/sie.c | 113 ++++++++++++++++++++++++++++++++++++++++++++ s390x/unittests.cfg | 3 ++ 3 files changed, 117 insertions(+) create mode 100644 s390x/sie.c diff --git a/s390x/Makefile b/s390x/Makefile index e0bccc8..9e6e60d 100644 --- a/s390x/Makefile +++ b/s390x/Makefile @@ -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),) diff --git a/s390x/sie.c b/s390x/sie.c new file mode 100644 index 0000000..cfc746f --- /dev/null +++ b/s390x/sie.c @@ -0,0 +1,113 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static u8 *guest; +static u8 *guest_instr; +static struct vm vm; + +static void handle_validity(struct vm *vm) +{ + report(0, "VALIDITY: %x", vm->sblk->ipb >> 16); +} + +static void sie(struct vm *vm) +{ + while (vm->sblk->icptcode == 0) { + sie64a(vm->sblk, &vm->save_area); + if (vm->sblk->icptcode == ICPT_VALIDITY) + handle_validity(vm); + } + vm->save_area.guest.grs[14] = vm->sblk->gg14; + vm->save_area.guest.grs[15] = vm->sblk->gg15; +} + +static void sblk_cleanup(struct vm *vm) +{ + vm->sblk->icptcode = 0; +} + +static void test_diag(u32 instr) +{ + vm.sblk->gpsw.addr = PAGE_SIZE * 2; + vm.sblk->gpsw.mask = 0x0000000180000000ULL; + + memset(guest_instr, 0, PAGE_SIZE); + memcpy(guest_instr, &instr, 4); + sie(&vm); + report(vm.sblk->icptcode == ICPT_INST && + vm.sblk->ipa == instr >> 16 && vm.sblk->ipb == instr << 16, + "Intercept data"); + sblk_cleanup(&vm); +} + +static struct { + const char *name; + u32 instr; +} tests[] = { + { "10", 0x83020010 }, + { "44", 0x83020044 }, + { "9c", 0x8302009c }, + { NULL, 0 } +}; + +static void test_diags(void) +{ + int i; + + for (i = 0; tests[i].name; i++) { + report_prefix_push(tests[i].name); + test_diag(tests[i].instr); + report_prefix_pop(); + } +} + +static void setup_guest(void) +{ + setup_vm(); + + /* Allocate 1MB as guest memory */ + guest = alloc_pages(8); + /* The first two pages are the lowcore */ + guest_instr = guest + PAGE_SIZE * 2; + + vm.sblk = alloc_page(); + + vm.sblk->cpuflags = CPUSTAT_ZARCH | CPUSTAT_RUNNING; + vm.sblk->prefix = 0; + /* + * Pageable guest with the same ASCE as the test programm, but + * the guest memory 0x0 is offset to start at the allocated + * guest pages and end after 1MB. + * + * It's not pretty but faster and easier than managing guest ASCEs. + */ + vm.sblk->mso = (u64)guest; + vm.sblk->msl = (u64)guest; + vm.sblk->ihcpu = 0xffff; + + vm.sblk->crycbd = (uint64_t)alloc_page(); +} + +int main(void) +{ + report_prefix_push("sie"); + if (!sclp_facilities.has_sief2) { + report_skip("SIEF2 facility unavailable"); + goto done; + } + + setup_guest(); + test_diags(); +done: + report_prefix_pop(); + return report_summary(); +} diff --git a/s390x/unittests.cfg b/s390x/unittests.cfg index 3feb8bc..2298be6 100644 --- a/s390x/unittests.cfg +++ b/s390x/unittests.cfg @@ -96,3 +96,6 @@ smp = 2 [uv-guest] file = uv-guest.elf + +[sie] +file = sie.elf -- 2.25.1