kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [kvm-unit-tests PATCH v3 0/1] Test spec exception interception
@ 2021-10-22 13:10 Janis Schoetterl-Glausch
  2021-10-22 13:10 ` [kvm-unit-tests PATCH v3 1/1] s390x: Add specification exception interception test Janis Schoetterl-Glausch
  0 siblings, 1 reply; 11+ messages in thread
From: Janis Schoetterl-Glausch @ 2021-10-22 13:10 UTC (permalink / raw)
  To: Thomas Huth, Janosch Frank, Claudio Imbrenda
  Cc: Janis Schoetterl-Glausch, kvm

When specification exception interpretation is enabled, specification
exceptions need not result in interceptions.
However, if the exception is due to an invalid program new PSW,
interception must occur.
Test this.
Also test that interpretation does occur if interpretation is disabled.

v2 -> v3
	drop patch converting assert to report
	drop non-ascii symbol
	use snippet constants

v1 -> v2
	Add license and test description
	Use lowcore pointer instead of magic value for program new PSW
		-> need to get rid of assert in arch_def.h
	Do not use odd program new PSW, even if irrelevant
	Use SIE lib
	Reword messages
	Fix nits

Janis Schoetterl-Glausch (1):
  s390x: Add specification exception interception test

 s390x/Makefile             |  2 +
 lib/s390x/sie.h            |  1 +
 s390x/snippets/c/spec_ex.c | 21 ++++++++++
 s390x/spec_ex-sie.c        | 82 ++++++++++++++++++++++++++++++++++++++
 s390x/unittests.cfg        |  3 ++
 5 files changed, 109 insertions(+)
 create mode 100644 s390x/snippets/c/spec_ex.c
 create mode 100644 s390x/spec_ex-sie.c

Range-diff against v2:
1:  f8abbae ! 1:  319eb08 s390x: Add specification exception interception test
    @@ s390x/Makefile: tests += $(TEST_DIR)/mvpg.elf
      
      tests_binary = $(patsubst %.elf,%.bin,$(tests))
      ifneq ($(HOST_KEY_DOCUMENT),)
    -@@ s390x/Makefile: snippet_asmlib = $(SNIPPET_DIR)/c/cstart.o
    +@@ s390x/Makefile: snippet_asmlib = $(SNIPPET_DIR)/c/cstart.o 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
    @@ s390x/snippets/c/spec_ex.c (new)
     @@
     +// SPDX-License-Identifier: GPL-2.0-only
     +/*
    -+ * <utf-8 (C) symbol> Copyright IBM Corp. 2021
    ++ * Copyright IBM Corp. 2021
     + *
     + * Snippet used by specification exception interception test.
     + */
    -+#include <stdint.h>
    ++#include <libcflat.h>
    ++#include <bitops.h>
     +#include <asm/arch_def.h>
     +
     +__attribute__((section(".text"))) int main(void)
    @@ s390x/snippets/c/spec_ex.c (new)
     +	uint64_t bad_psw = 0;
     +
     +	/* PSW bit 12 has no name or meaning and must be 0 */
    -+	lowcore->pgm_new_psw.mask = 1UL << (63 - 12);
    ++	lowcore->pgm_new_psw.mask = BIT(63 - 12);
     +	lowcore->pgm_new_psw.addr = 0xdeadbeee;
     +	asm volatile ("lpsw %0" :: "Q"(bad_psw));
     +	return 0;
    @@ s390x/spec_ex-sie.c (new)
     @@
     +// SPDX-License-Identifier: GPL-2.0-only
     +/*
    -+ * <utf-8 (C) symbol> Copyright IBM Corp. 2021
    ++ * Copyright IBM Corp. 2021
     + *
     + * Specification exception interception test.
     + * Checks that specification exception interceptions occur as expected when
    @@ s390x/spec_ex-sie.c (new)
     +#include <alloc_page.h>
     +#include <vm.h>
     +#include <sie.h>
    ++#include <snippet.h>
     +
     +static struct vm vm;
    -+extern const char _binary_s390x_snippets_c_spec_ex_gbin_start[];
    -+extern const char _binary_s390x_snippets_c_spec_ex_gbin_end[];
    ++extern const char SNIPPET_NAME_START(c, spec_ex)[];
    ++extern const char SNIPPET_NAME_END(c, spec_ex)[];
     +
     +static void setup_guest(void)
     +{
     +	char *guest;
    -+	int binary_size = ((uintptr_t)_binary_s390x_snippets_c_spec_ex_gbin_end -
    -+			   (uintptr_t)_binary_s390x_snippets_c_spec_ex_gbin_start);
    ++	int binary_size = SNIPPET_LEN(c, spec_ex);
     +
     +	setup_vm();
     +	guest = alloc_pages(8);
    -+	memcpy(guest, _binary_s390x_snippets_c_spec_ex_gbin_start, binary_size);
    ++	memcpy(guest, SNIPPET_NAME_START(c, spec_ex), binary_size);
     +	sie_guest_create(&vm, (uint64_t) guest, HPAGE_SIZE);
     +}
     +
     +static void reset_guest(void)
     +{
    -+	vm.sblk->gpsw.addr = PAGE_SIZE * 4;
    -+	vm.sblk->gpsw.mask = PSW_MASK_64;
    ++	vm.sblk->gpsw = snippet_psw;
     +	vm.sblk->icptcode = 0;
     +}
     +

base-commit: 3ac97f8fc847d05d0a5555aefd34e2cac26fdc0c
-- 
2.31.1


^ permalink raw reply	[flat|nested] 11+ messages in thread
* [kvm-unit-tests PATCH] s390x: Add strict mode to specification exception interpretation test
@ 2022-02-25 17:23 Janis Schoetterl-Glausch
  2022-02-28 13:27 ` Claudio Imbrenda
  0 siblings, 1 reply; 11+ messages in thread
From: Janis Schoetterl-Glausch @ 2022-02-25 17:23 UTC (permalink / raw)
  To: Thomas Huth, Janosch Frank, Claudio Imbrenda
  Cc: Janis Schoetterl-Glausch, David Hildenbrand, kvm, linux-s390

While specification exception interpretation is not required to occur,
it can be useful for automatic regression testing to fail the test if it
does not occur.
Add a `--strict` argument to enable this.
`--strict` takes a list of machine types (as reported by STIDP)
for which to enable strict mode, for example
`--strict 8562,8561,3907,3906,2965,2964`
will enable it for models z15 - z13.
Alternatively, strict mode can be enabled for all but the listed machine
types by prefixing the list with a `!`, for example
`--strict !1090,1091,2064,2066,2084,2086,2094,2096,2097,2098,2817,2818,2827,2828`
will enable it for z/Architecture models except those older than z13.

Signed-off-by: Janis Schoetterl-Glausch <scgl@linux.ibm.com>
---
Range-diff:
1:  5d91f693 < -:  -------- s390x: Add specification exception interception test
2:  950eafd7 ! 1:  e9c36970 s390x: Add strict mode to specification exception interpretation test
    @@ s390x/spec_ex-sie.c: static void reset_guest(void)
     -static void test_spec_ex_sie(void)
     +static void test_spec_ex_sie(bool strict)
      {
    ++	const char *msg;
    ++
      	setup_guest();
      
    + 	report_prefix_push("SIE spec ex interpretation");
     @@ s390x/spec_ex-sie.c: static void test_spec_ex_sie(void)
      	report(vm.sblk->icptcode == ICPT_PROGI
      	       && vm.sblk->iprcc == PGM_INT_CODE_SPECIFICATION,
      	       "Received specification exception intercept");
     -	if (vm.sblk->gpsw.addr == 0xdeadbeee)
     -		report_info("Interpreted initial exception, intercepted invalid program new PSW exception");
    --	else
    --		report_info("Did not interpret initial exception");
    -+	{
    -+		const char *msg;
    -+
    -+		msg = "Interpreted initial exception, intercepted invalid program new PSW exception";
    -+		if (strict)
    -+			report(vm.sblk->gpsw.addr == 0xdeadbeee, msg);
    -+		else if (vm.sblk->gpsw.addr == 0xdeadbeee)
    -+			report_info(msg);
    -+		else
    -+			report_info("Did not interpret initial exception");
    -+	}
    ++	msg = "Interpreted initial exception, intercepted invalid program new PSW exception";
    ++	if (strict)
    ++		report(vm.sblk->gpsw.addr == 0xdeadbeee, msg);
    ++	else if (vm.sblk->gpsw.addr == 0xdeadbeee)
    ++		report_info(msg);
    + 	else
    + 		report_info("Did not interpret initial exception");
      	report_prefix_pop();
      	report_prefix_pop();
      }
      
    -+static bool parse_strict(char **argv)
    ++static bool parse_strict(int argc, char **argv)
     +{
     +	uint16_t machine_id;
     +	char *list;
     +	bool ret;
     +
    -+	if (!*argv)
    ++	if (argc < 1)
     +		return false;
    -+	if (strcmp("--strict", *argv))
    ++	if (strcmp("--strict", argv[0]))
     +		return false;
     +
     +	machine_id = get_machine_id();
    -+	list = argv[1];
    -+	if (!list) {
    ++	if (argc < 2) {
     +		printf("No argument to --strict, ignoring\n");
     +		return false;
     +	}
    ++	list = argv[1];
     +	if (list[0] == '!') {
     +		ret = true;
     +		list++;
    @@ s390x/spec_ex-sie.c: int main(int argc, char **argv)
      	}
      
     -	test_spec_ex_sie();
    -+	test_spec_ex_sie(parse_strict(argv + 1));
    ++	test_spec_ex_sie(parse_strict(argc - 1, argv + 1));
      out:
      	return report_summary();
      }

 s390x/spec_ex-sie.c | 53 +++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 49 insertions(+), 4 deletions(-)

diff --git a/s390x/spec_ex-sie.c b/s390x/spec_ex-sie.c
index 5dea4115..071110e3 100644
--- a/s390x/spec_ex-sie.c
+++ b/s390x/spec_ex-sie.c
@@ -7,6 +7,7 @@
  * specification exception interpretation is off/on.
  */
 #include <libcflat.h>
+#include <stdlib.h>
 #include <sclp.h>
 #include <asm/page.h>
 #include <asm/arch_def.h>
@@ -36,8 +37,10 @@ static void reset_guest(void)
 	vm.sblk->icptcode = 0;
 }
 
-static void test_spec_ex_sie(void)
+static void test_spec_ex_sie(bool strict)
 {
+	const char *msg;
+
 	setup_guest();
 
 	report_prefix_push("SIE spec ex interpretation");
@@ -61,14 +64,56 @@ static void test_spec_ex_sie(void)
 	report(vm.sblk->icptcode == ICPT_PROGI
 	       && vm.sblk->iprcc == PGM_INT_CODE_SPECIFICATION,
 	       "Received specification exception intercept");
-	if (vm.sblk->gpsw.addr == 0xdeadbeee)
-		report_info("Interpreted initial exception, intercepted invalid program new PSW exception");
+	msg = "Interpreted initial exception, intercepted invalid program new PSW exception";
+	if (strict)
+		report(vm.sblk->gpsw.addr == 0xdeadbeee, msg);
+	else if (vm.sblk->gpsw.addr == 0xdeadbeee)
+		report_info(msg);
 	else
 		report_info("Did not interpret initial exception");
 	report_prefix_pop();
 	report_prefix_pop();
 }
 
+static bool parse_strict(int argc, char **argv)
+{
+	uint16_t machine_id;
+	char *list;
+	bool ret;
+
+	if (argc < 1)
+		return false;
+	if (strcmp("--strict", argv[0]))
+		return false;
+
+	machine_id = get_machine_id();
+	if (argc < 2) {
+		printf("No argument to --strict, ignoring\n");
+		return false;
+	}
+	list = argv[1];
+	if (list[0] == '!') {
+		ret = true;
+		list++;
+	} else
+		ret = false;
+	while (true) {
+		long input = 0;
+
+		if (strlen(list) == 0)
+			return ret;
+		input = strtol(list, &list, 16);
+		if (*list == ',')
+			list++;
+		else if (*list != '\0')
+			break;
+		if (input == machine_id)
+			return !ret;
+	}
+	printf("Invalid --strict argument \"%s\", ignoring\n", list);
+	return ret;
+}
+
 int main(int argc, char **argv)
 {
 	if (!sclp_facilities.has_sief2) {
@@ -76,7 +121,7 @@ int main(int argc, char **argv)
 		goto out;
 	}
 
-	test_spec_ex_sie();
+	test_spec_ex_sie(parse_strict(argc - 1, argv + 1));
 out:
 	return report_summary();
 }

base-commit: 257c962f3d1b2d0534af59de4ad18764d734903a
-- 
2.33.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2022-03-03  9:43 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-22 13:10 [kvm-unit-tests PATCH v3 0/1] Test spec exception interception Janis Schoetterl-Glausch
2021-10-22 13:10 ` [kvm-unit-tests PATCH v3 1/1] s390x: Add specification exception interception test Janis Schoetterl-Glausch
2021-10-25 12:25   ` Thomas Huth
2021-11-11  7:47   ` Thomas Huth
2021-11-16 11:57     ` Janis Schoetterl-Glausch
2021-11-25 14:47     ` [kvm-unit-tests PATCH] s390x: Add strict mode to specification exception interpretation test Janis Schoetterl-Glausch
2021-12-03 11:15       ` Thomas Huth
2021-12-03 11:46         ` Janis Schoetterl-Glausch
2022-02-25 17:23 Janis Schoetterl-Glausch
2022-02-28 13:27 ` Claudio Imbrenda
2022-03-03  9:43   ` Janis Schoetterl-Glausch

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).