diff mbox series

[kvm-unit-tests,v1,1/8] s390x: Add more tests for MSCH

Message ID 20220121150931.371720-2-nrb@linux.ibm.com (mailing list archive)
State New, archived
Headers show
Series s390x: Extend instruction interception tests | expand

Commit Message

Nico Boehr Jan. 21, 2022, 3:09 p.m. UTC
We already have some coverage for MSCH, but there are more cases to test
for:

- invalid SCHIB structure. We cover that by setting reserved bits 0, 1,
  6 and 7 in the flags of the PMCW.
  This test currently fails because of a QEMU bug, a fix
  is available (see "[PATCH qemu] s390x/css: fix PMCW invalid mask")
- a pointer to an unaligned SCHIB. We cover misalignment by 1
  and 2 bytes. Using pointer to valid memory avoids messing up
  random memory in case of test failures.

Here's the QEMU PMCW invalid mask fix: https://lists.nongnu.org/archive/html/qemu-s390x/2021-12/msg00100.html

Signed-off-by: Nico Boehr <nrb@linux.ibm.com>
Reviewed-by: Janosch Frank <frankja@linux.ibm.com>
Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
---
 s390x/css.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)

Comments

Thomas Huth Jan. 25, 2022, 11:54 a.m. UTC | #1
On 21/01/2022 16.09, Nico Boehr wrote:
> We already have some coverage for MSCH, but there are more cases to test
> for:
> 
> - invalid SCHIB structure. We cover that by setting reserved bits 0, 1,
>    6 and 7 in the flags of the PMCW.
>    This test currently fails because of a QEMU bug, a fix
>    is available (see "[PATCH qemu] s390x/css: fix PMCW invalid mask")
> - a pointer to an unaligned SCHIB. We cover misalignment by 1
>    and 2 bytes. Using pointer to valid memory avoids messing up
>    random memory in case of test failures.
> 
> Here's the QEMU PMCW invalid mask fix: https://lists.nongnu.org/archive/html/qemu-s390x/2021-12/msg00100.html
> 
> Signed-off-by: Nico Boehr <nrb@linux.ibm.com>
> Reviewed-by: Janosch Frank <frankja@linux.ibm.com>
> Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
> ---
>   s390x/css.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
>   1 file changed, 51 insertions(+)
> 
> diff --git a/s390x/css.c b/s390x/css.c
> index 881206ba1cef..afe1f71bb576 100644
> --- a/s390x/css.c
> +++ b/s390x/css.c
> @@ -27,6 +27,8 @@ static int test_device_sid;
>   static struct senseid *senseid;
>   struct ccw1 *ccw;
>   
> +char alignment_test_page[PAGE_SIZE] __attribute__((aligned(PAGE_SIZE)));

Alternatively, you could also use alloc_page() in that new function... not 
sure what's nicer, though.

>   static void test_enumerate(void)
>   {
>   	test_device_sid = css_enumerate();
> @@ -331,6 +333,54 @@ static void test_schm_fmt1(void)
>   	free_io_mem(mb1, sizeof(struct measurement_block_format1));
>   }
>   
> +static void test_msch(void)
> +{
> +	const int align_to = 4;
> +	int cc;
> +	int invalid_pmcw_flags[] = {0, 1, 6, 7};
> +	int invalid_flag;
> +	uint16_t old_pmcw_flags;
> +
> +	if (!test_device_sid) {
> +		report_skip("No device");
> +		return;
> +	}
> +
> +	cc = stsch(test_device_sid, &schib);
> +	if (cc) {
> +		report_fail("stsch: sch %08x failed with cc=%d", test_device_sid, cc);
> +		return;
> +	}
> +
> +	report_prefix_push("Unaligned");
> +	for (int i = 1; i < align_to; i *= 2) {
> +		report_prefix_pushf("%d", i);
> +
> +		expect_pgm_int();
> +		msch(test_device_sid, (struct schib *)(alignment_test_page + i));
> +		check_pgm_int_code(PGM_INT_CODE_SPECIFICATION);
> +
> +		report_prefix_pop();
> +	}
> +	report_prefix_pop();
> +
> +	report_prefix_push("Invalid SCHIB");
> +	old_pmcw_flags = schib.pmcw.flags;
> +	for (int i = 0; i < ARRAY_SIZE(invalid_pmcw_flags); i++) {
> +		invalid_flag = invalid_pmcw_flags[i];
> +
> +		report_prefix_pushf("PMCW flag bit %d set", invalid_flag);
> +
> +		schib.pmcw.flags = old_pmcw_flags | BIT(15 - invalid_flag);
> +		expect_pgm_int();
> +		msch(test_device_sid, &schib);
> +		check_pgm_int_code(PGM_INT_CODE_OPERAND);
> +
> +		report_prefix_pop();
> +	}

Maybe restore schib.pmcw.flags = old_pmcw_flags at the end, in case someone 
wants to add more tests later?

> +	report_prefix_pop();
> +}
> +
>   static struct {
>   	const char *name;
>   	void (*func)(void);
> @@ -343,6 +393,7 @@ static struct {
>   	{ "measurement block (schm)", test_schm },
>   	{ "measurement block format0", test_schm_fmt0 },
>   	{ "measurement block format1", test_schm_fmt1 },
> +	{ "msch", test_msch },
>   	{ NULL, NULL }
>   };
>   

Reviewed-by: Thomas Huth <thuth@redhat.com>
Nico Boehr Jan. 25, 2022, 12:57 p.m. UTC | #2
On Tue, 2022-01-25 at 12:54 +0100, Thomas Huth wrote:
> On 21/01/2022 16.09, Nico Boehr wrote:
> 
[...]
> > diff --git a/s390x/css.c b/s390x/css.c
> > index 881206ba1cef..afe1f71bb576 100644
> > --- a/s390x/css.c
> > +++ b/s390x/css.c
> > @@ -27,6 +27,8 @@ static int test_device_sid;
> >   static struct senseid *senseid;
> >   struct ccw1 *ccw;
> >   
> > +char alignment_test_page[PAGE_SIZE]
> > __attribute__((aligned(PAGE_SIZE)));
> 
> Alternatively, you could also use alloc_page() in that new
> function... not 
> sure what's nicer, though.

I don't have a strong opinion. Happy to change to whatever you or the
others prefer.


> >   
> > +static void test_msch(void)
> > +{
[...]
> > +
> > +       report_prefix_push("Invalid SCHIB");
> > +       old_pmcw_flags = schib.pmcw.flags;
> > +       for (int i = 0; i < ARRAY_SIZE(invalid_pmcw_flags); i++) {
> > +               invalid_flag = invalid_pmcw_flags[i];
> > +
> > +               report_prefix_pushf("PMCW flag bit %d set",
> > invalid_flag);
> > +
> > +               schib.pmcw.flags = old_pmcw_flags | BIT(15 -
> > invalid_flag);
> > +               expect_pgm_int();
> > +               msch(test_device_sid, &schib);
> > +               check_pgm_int_code(PGM_INT_CODE_OPERAND);
> > +
> > +               report_prefix_pop();
> > +       }
> 
> Maybe restore schib.pmcw.flags = old_pmcw_flags at the end, in case
> someone 
> wants to add more tests later?

Yes, awesome idea, will do.

> 
> > +       report_prefix_pop();
> > +}
> > +
> >   static struct {
> >         const char *name;
> >         void (*func)(void);
> > @@ -343,6 +393,7 @@ static struct {
> >         { "measurement block (schm)", test_schm },
> >         { "measurement block format0", test_schm_fmt0 },
> >         { "measurement block format1", test_schm_fmt1 },
> > +       { "msch", test_msch },
> >         { NULL, NULL }
> >   };
> >   
> 
> Reviewed-by: Thomas Huth <thuth@redhat.com>
> 

Thanks.

Nico
diff mbox series

Patch

diff --git a/s390x/css.c b/s390x/css.c
index 881206ba1cef..afe1f71bb576 100644
--- a/s390x/css.c
+++ b/s390x/css.c
@@ -27,6 +27,8 @@  static int test_device_sid;
 static struct senseid *senseid;
 struct ccw1 *ccw;
 
+char alignment_test_page[PAGE_SIZE] __attribute__((aligned(PAGE_SIZE)));
+
 static void test_enumerate(void)
 {
 	test_device_sid = css_enumerate();
@@ -331,6 +333,54 @@  static void test_schm_fmt1(void)
 	free_io_mem(mb1, sizeof(struct measurement_block_format1));
 }
 
+static void test_msch(void)
+{
+	const int align_to = 4;
+	int cc;
+	int invalid_pmcw_flags[] = {0, 1, 6, 7};
+	int invalid_flag;
+	uint16_t old_pmcw_flags;
+
+	if (!test_device_sid) {
+		report_skip("No device");
+		return;
+	}
+
+	cc = stsch(test_device_sid, &schib);
+	if (cc) {
+		report_fail("stsch: sch %08x failed with cc=%d", test_device_sid, cc);
+		return;
+	}
+
+	report_prefix_push("Unaligned");
+	for (int i = 1; i < align_to; i *= 2) {
+		report_prefix_pushf("%d", i);
+
+		expect_pgm_int();
+		msch(test_device_sid, (struct schib *)(alignment_test_page + i));
+		check_pgm_int_code(PGM_INT_CODE_SPECIFICATION);
+
+		report_prefix_pop();
+	}
+	report_prefix_pop();
+
+	report_prefix_push("Invalid SCHIB");
+	old_pmcw_flags = schib.pmcw.flags;
+	for (int i = 0; i < ARRAY_SIZE(invalid_pmcw_flags); i++) {
+		invalid_flag = invalid_pmcw_flags[i];
+
+		report_prefix_pushf("PMCW flag bit %d set", invalid_flag);
+
+		schib.pmcw.flags = old_pmcw_flags | BIT(15 - invalid_flag);
+		expect_pgm_int();
+		msch(test_device_sid, &schib);
+		check_pgm_int_code(PGM_INT_CODE_OPERAND);
+
+		report_prefix_pop();
+	}
+	report_prefix_pop();
+}
+
 static struct {
 	const char *name;
 	void (*func)(void);
@@ -343,6 +393,7 @@  static struct {
 	{ "measurement block (schm)", test_schm },
 	{ "measurement block format0", test_schm_fmt0 },
 	{ "measurement block format1", test_schm_fmt1 },
+	{ "msch", test_msch },
 	{ NULL, NULL }
 };