From: Janosch Frank <frankja@linux.ibm.com>
To: Nico Boehr <nrb@linux.ibm.com>, imbrenda@linux.ibm.com, thuth@redhat.com
Cc: kvm@vger.kernel.org, linux-s390@vger.kernel.org
Subject: Re: [kvm-unit-tests PATCH v3 6/6] s390x: add a test for SIE without MSO/MSL
Date: Mon, 5 Jun 2023 11:57:58 +0200 [thread overview]
Message-ID: <ab1047c5-77f1-d68b-cf05-4bcda44909ed@linux.ibm.com> (raw)
In-Reply-To: <20230601070202.152094-7-nrb@linux.ibm.com>
On 6/1/23 09:02, Nico Boehr wrote:
> Since we now have the ability to run guests without MSO/MSL, add a test
> to make sure this doesn't break.
>
> Signed-off-by: Nico Boehr <nrb@linux.ibm.com>
> ---
> s390x/Makefile | 2 +
> s390x/sie-dat.c | 120 +++++++++++++++++++++++++++++++++++++
> s390x/snippets/c/sie-dat.c | 58 ++++++++++++++++++
> s390x/unittests.cfg | 3 +
> 4 files changed, 183 insertions(+)
> 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 a80db538810e..4921669ee4c3 100644
> --- a/s390x/Makefile
> +++ b/s390x/Makefile
> @@ -40,6 +40,7 @@ tests += $(TEST_DIR)/panic-loop-pgm.elf
> tests += $(TEST_DIR)/migration-sck.elf
> tests += $(TEST_DIR)/exittime.elf
> tests += $(TEST_DIR)/ex.elf
> +tests += $(TEST_DIR)/sie-dat.elf
>
> pv-tests += $(TEST_DIR)/pv-diags.elf
>
> @@ -120,6 +121,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/snippet-pv-diag-yield.gbin
> diff --git a/s390x/sie-dat.c b/s390x/sie-dat.c
> new file mode 100644
> index 000000000000..c490a2aa825c
> --- /dev/null
> +++ b/s390x/sie-dat.c
> @@ -0,0 +1,120 @@
> +/* 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/asm-offsets.h>
I only did a cursory glance and wasn't able to see a use for this include.
> +#include <asm-generic/barrier.h>
> +#include <asm/pgtable.h>
> +#include <mmu.h>
> +#include <asm/page.h>
> +#include <asm/facility.h>
The sclp.h include should be enough, no?
You're not using test_facility() as far as I can see.
> +#include <asm/interrupt.h>
> +#include <asm/mem.h>
> +#include <alloc_page.h>
> +#include <sclp.h> > +#include <sie.h>
> +#include <snippet.h>
> +
> +static struct vm vm;
> +static pgd_t *guest_root;
> +
> +/* keep in sync with TEST_PAGE_COUNT in s390x/snippets/c/sie-dat.c */
> +#define GUEST_TEST_PAGE_COUNT 10
> +
> +/* keep in sync with TOTAL_PAGE_COUNT in s390x/snippets/c/sie-dat.c */
> +#define GUEST_TOTAL_PAGE_COUNT 256
> +
> +static void test_sie_dat(void)
> +{
> + uint8_t r1;
> + bool contents_match;
> + uint64_t test_page_gpa, test_page_hpa;
> + uint8_t *test_page_hva;
> +
> + /* guest will tell us the guest physical address of the test buffer */
> + sie(&vm);
> +
> + 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(vm.sblk->icptcode == ICPT_INST &&
> + (vm.sblk->ipa & 0xFF00) == 0x8300 && vm.sblk->ipb == 0x9c0000,
> + "test buffer gpa=0x%lx hva=%p", test_page_gpa, test_page_hva);
You could rebase on my pv_icptdata.h patch.
Also the report string and boolean don't really relate to each other.
Not every exit needs to be a report.
Some should rather be asserts() or report_info()s.
> +
> + /* guest will now write to the test buffer and we verify the contents */
> + sie(&vm);
> + report(vm.sblk->icptcode == ICPT_INST &&
> + vm.sblk->ipa == 0x8300 && vm.sblk->ipb == 0x440000,
> + "guest wrote to test buffer");
Yup pv_icptdata.h
> +
> + contents_match = true;
> + for (unsigned int i = 0; i < GUEST_TEST_PAGE_COUNT; i++) {
> + uint8_t expected_val = 42 + i;
Just because you can doesn't mean that you have to.
At least leave a \n when declaring new variables...
> + 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_prefix_pop();
> +}
> +
[...]
> +}
> diff --git a/s390x/snippets/c/sie-dat.c b/s390x/snippets/c/sie-dat.c
> new file mode 100644
> index 000000000000..e156d0c36c4c
> --- /dev/null
> +++ b/s390x/snippets/c/sie-dat.c
> @@ -0,0 +1,58 @@
> +/* 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 <stddef.h>
> +#include <inttypes.h>
> +#include <string.h>
> +#include <asm-generic/page.h>
> +
> +/* keep in sync with GUEST_TEST_PAGE_COUNT in s390x/sie-dat.c */
> +#define TEST_PAGE_COUNT 10
> +static uint8_t test_page[TEST_PAGE_COUNT * PAGE_SIZE] __attribute__((__aligned__(PAGE_SIZE)));
> +
> +/* keep in sync with GUEST_TOTAL_PAGE_COUNT in s390x/sie-dat.c */
> +#define TOTAL_PAGE_COUNT 256
> +
> +static inline void force_exit(void)
> +{
> + asm volatile("diag 0,0,0x44\n");
> +}
> +
> +static inline void force_exit_value(uint64_t val)
> +{
> + asm volatile(
> + "diag %[val],0,0x9c\n"
> + : : [val] "d"(val)
> + );
> +}
It feels like these need to go into a snippet lib.
> +
> +__attribute__((section(".text"))) int main(void)
The attribute shouldn't be needed anymore.
> +{
> + uint8_t *invalid_ptr;
> +
> + memset(test_page, 0, sizeof(test_page));
> + /* tell the host the page's physical address (we're running DAT off) */
> + force_exit_value((uint64_t)test_page);
> +
> + /* write some value to the page so the host can verify it */
> + for (size_t i = 0; i < TEST_PAGE_COUNT; i++)
Why is i a size_t type?
> + test_page[i * PAGE_SIZE] = 42 + i;
> +
> + /* indicate we've written all pages */
> + force_exit();
> +
> + /* the first unmapped address */
> + invalid_ptr = (uint8_t *)(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 b61faf0737c3..24cd27202a08 100644
> --- a/s390x/unittests.cfg
> +++ b/s390x/unittests.cfg
> @@ -218,3 +218,6 @@ extra_params = -append '--parallel'
>
> [execute]
> file = ex.elf
> +
> +[sie-dat]
> +file = sie-dat.elf
next prev parent reply other threads:[~2023-06-05 9:58 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-01 7:01 [kvm-unit-tests PATCH v3 0/6] s390x: Add support for running guests without MSO/MSL Nico Boehr
2023-06-01 7:01 ` [kvm-unit-tests PATCH v3 1/6] lib: s390x: introduce bitfield for PSW mask Nico Boehr
2023-06-01 7:42 ` Janosch Frank
2023-06-05 10:35 ` Claudio Imbrenda
2023-06-05 14:23 ` Janosch Frank
2023-06-07 15:56 ` Nico Boehr
2023-06-07 16:19 ` Claudio Imbrenda
2023-06-01 7:01 ` [kvm-unit-tests PATCH v3 2/6] s390x: add function to set DAT mode for all interrupts Nico Boehr
2023-06-05 8:42 ` Janosch Frank
2023-06-15 12:44 ` Nico Boehr
2023-06-01 7:01 ` [kvm-unit-tests PATCH v3 3/6] s390x: sie: switch to home space mode before entering SIE Nico Boehr
2023-06-05 9:03 ` Janosch Frank
2023-06-15 13:09 ` Nico Boehr
2023-06-01 7:02 ` [kvm-unit-tests PATCH v3 4/6] s390x: lib: don't forward PSW when handling exception in SIE Nico Boehr
2023-06-05 9:11 ` Janosch Frank
2023-06-05 10:42 ` Claudio Imbrenda
2023-06-01 7:02 ` [kvm-unit-tests PATCH v3 5/6] s390x: lib: sie: don't reenter SIE on pgm int Nico Boehr
2023-06-05 9:30 ` Janosch Frank
2023-06-05 10:44 ` Claudio Imbrenda
2023-06-30 14:59 ` Nico Boehr
2023-06-30 15:04 ` Janosch Frank
2023-06-30 15:53 ` Claudio Imbrenda
2023-06-01 7:02 ` [kvm-unit-tests PATCH v3 6/6] s390x: add a test for SIE without MSO/MSL Nico Boehr
2023-06-05 9:57 ` Janosch Frank [this message]
2023-07-10 14:29 ` Nico Boehr
2023-07-10 15:05 ` 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=ab1047c5-77f1-d68b-cf05-4bcda44909ed@linux.ibm.com \
--to=frankja@linux.ibm.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