From: Janosch Frank <frankja@linux.ibm.com>
To: Thomas Huth <thuth@redhat.com>, kvm@vger.kernel.org
Cc: linux-s390@vger.kernel.org, imbrenda@linux.ibm.com,
david@redhat.com, cohuck@redhat.com
Subject: Re: [kvm-unit-tests PATCH v2 3/3] s390x: mvpg: Add SIE mvpg test
Date: Mon, 5 Jul 2021 11:37:03 +0200 [thread overview]
Message-ID: <8a742d45-bb49-d130-604a-da1e11150ef3@linux.ibm.com> (raw)
In-Reply-To: <d4966f2c-89b4-94b7-0dc7-df69534c2d7a@redhat.com>
On 7/5/21 9:24 AM, Thomas Huth wrote:
> On 29/06/2021 15.18, Janosch Frank wrote:
>> Let's also check the PEI values to make sure our VSIE implementation
>> is correct.
>>
>> Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
>> ---
>> s390x/Makefile | 2 +
>> s390x/mvpg-sie.c | 151 ++++++++++++++++++++++++++++++++
>> s390x/snippets/c/mvpg-snippet.c | 33 +++++++
>> s390x/unittests.cfg | 3 +
>> 4 files changed, 189 insertions(+)
>> create mode 100644 s390x/mvpg-sie.c
>> create mode 100644 s390x/snippets/c/mvpg-snippet.c
>>
>> diff --git a/s390x/Makefile b/s390x/Makefile
>> index ba32f4c..07af26d 100644
>> --- a/s390x/Makefile
>> +++ b/s390x/Makefile
>> @@ -23,6 +23,7 @@ tests += $(TEST_DIR)/sie.elf
>> tests += $(TEST_DIR)/mvpg.elf
>> tests += $(TEST_DIR)/uv-host.elf
>> tests += $(TEST_DIR)/edat.elf
>> +tests += $(TEST_DIR)/mvpg-sie.elf
>>
>> tests_binary = $(patsubst %.elf,%.bin,$(tests))
>> ifneq ($(HOST_KEY_DOCUMENT),)
>> @@ -82,6 +83,7 @@ snippet_asmlib = $(SNIPPET_DIR)/c/cstart.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
>>
>> $(SNIPPET_DIR)/asm/%.gbin: $(SNIPPET_DIR)/asm/%.o $(FLATLIBS)
>> $(OBJCOPY) -O binary $(patsubst %.gbin,%.o,$@) $@
>> diff --git a/s390x/mvpg-sie.c b/s390x/mvpg-sie.c
>> new file mode 100644
>> index 0000000..3536c6a
>> --- /dev/null
>> +++ b/s390x/mvpg-sie.c
>> @@ -0,0 +1,151 @@
>> +#include <libcflat.h>
>> +#include <asm/asm-offsets.h>
>> +#include <asm-generic/barrier.h>
>> +#include <asm/pgtable.h>
>> +#include <mmu.h>
>> +#include <asm/page.h>
>> +#include <asm/facility.h>
>> +#include <asm/mem.h>
>> +#include <alloc_page.h>
>> +#include <vm.h>
>> +#include <sclp.h>
>> +#include <sie.h>
>> +
>> +static u8 *guest;
>> +static u8 *guest_instr;
>> +static struct vm vm;
>> +
>> +static uint8_t *src;
>> +static uint8_t *dst;
>> +static uint8_t *cmp;
>> +
>> +extern const char _binary_s390x_snippets_c_mvpg_snippet_gbin_start[];
>> +extern const char _binary_s390x_snippets_c_mvpg_snippet_gbin_end[];
>> +int binary_size;
>> +
>> +static void sie(struct vm *vm)
>> +{
>> + /* Reset icptcode so we don't trip over it below */
>> + vm->sblk->icptcode = 0;
>> +
>> + while (vm->sblk->icptcode == 0) {
>> + sie64a(vm->sblk, &vm->save_area);
>> + if (vm->sblk->icptcode == ICPT_VALIDITY)
>> + assert(0);
>
> Please replace the above two lines with:
>
> assert(vm->sblk->icptcode != ICPT_VALIDITY);
Sure
>
>> + }
>> + vm->save_area.guest.grs[14] = vm->sblk->gg14;
>> + vm->save_area.guest.grs[15] = vm->sblk->gg15;
>> +}
>> +
>> +static void test_mvpg_pei(void)
>> +{
>> + uint64_t **pei_dst = (uint64_t **)((uintptr_t) vm.sblk + 0xc0);
>> + uint64_t **pei_src = (uint64_t **)((uintptr_t) vm.sblk + 0xc8);
>> +
>> + report_prefix_push("pei");
>> +
>> + report_prefix_push("src");
>> + memset(dst, 0, PAGE_SIZE);
>> + protect_page(src, PAGE_ENTRY_I);
>> + sie(&vm);
>> + report(vm.sblk->icptcode == ICPT_PARTEXEC, "Partial execution");
>> + report((uintptr_t)**pei_src == (uintptr_t)src + PAGE_ENTRY_I, "PEI_SRC correct");
>> + report((uintptr_t)**pei_dst == (uintptr_t)dst, "PEI_DST correct");
>> + unprotect_page(src, PAGE_ENTRY_I);
>> + report(!memcmp(cmp, dst, PAGE_SIZE), "Destination intact");
>> + /*
>> + * We need to execute the diag44 which is used as a blocker
>> + * behind the mvpg. It makes sure we fail the tests above if
>> + * the mvpg wouldn't have intercepted.
>> + */
>> + sie(&vm);
>> + /* Make sure we intercepted for the diag44 and nothing else */
>> + assert(vm.sblk->icptcode == ICPT_INST &&
>> + vm.sblk->ipa == 0x8300 && vm.sblk->ipb == 0x440000);
>> + report_prefix_pop();
>> +
>> + /* Clear PEI data for next check */
>> + report_prefix_push("dst");
>> + memset((uint64_t *)((uintptr_t) vm.sblk + 0xc0), 0, 16);
>> + memset(dst, 0, PAGE_SIZE);
>> + protect_page(dst, PAGE_ENTRY_I);
>> + sie(&vm);
>> + report(vm.sblk->icptcode == ICPT_PARTEXEC, "Partial execution");
>> + report((uintptr_t)**pei_src == (uintptr_t)src, "PEI_SRC correct");
>> + report((uintptr_t)**pei_dst == (uintptr_t)dst + PAGE_ENTRY_I, "PEI_DST correct");
>> + /* Needed for the memcmp and general cleanup */
>> + unprotect_page(dst, PAGE_ENTRY_I);
>> + report(!memcmp(cmp, dst, PAGE_SIZE), "Destination intact");
>> + report_prefix_pop();
>> +
>> + report_prefix_pop();
>> +}
>
> Still quite a lot of magic values in above code ... any chance to introduce
> some #defines finally?
Currently not really.
I added a comment for the diag 44 which should be enough right now. If
needed I can add a comment to the pei variables as well.
>
>> +static void test_mvpg(void)
>> +{
>> + int binary_size = ((uintptr_t)_binary_s390x_snippets_c_mvpg_snippet_gbin_end -
>> + (uintptr_t)_binary_s390x_snippets_c_mvpg_snippet_gbin_start);
>> +
>> + memcpy(guest, _binary_s390x_snippets_c_mvpg_snippet_gbin_start, binary_size);
>> + memset(src, 0x42, PAGE_SIZE);
>> + memset(dst, 0x43, PAGE_SIZE);
>> + sie(&vm);
>> + mb();
>
> I think you don't need the mb() here.
Right
>
>> + report(!memcmp(src, dst, PAGE_SIZE) && *dst == 0x42, "Page moved");
>> +}
>
> Thomas
>
next prev parent reply other threads:[~2021-07-05 9:37 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-29 13:18 [kvm-unit-tests PATCH v2 0/3] s390x: Add snippet support Janosch Frank
2021-06-29 13:18 ` [kvm-unit-tests PATCH v2 1/3] s390x: snippets: Add gitignore as well as linker script and start assembly Janosch Frank
2021-07-04 16:42 ` Thomas Huth
2021-06-29 13:18 ` [kvm-unit-tests PATCH v2 2/3] s390x: snippets: Add snippet compilation Janosch Frank
2021-06-29 13:18 ` [kvm-unit-tests PATCH v2 3/3] s390x: mvpg: Add SIE mvpg test Janosch Frank
2021-07-05 7:24 ` Thomas Huth
2021-07-05 9:37 ` Janosch Frank [this message]
2021-07-05 9:52 ` Thomas Huth
2021-07-05 9:56 ` 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=8a742d45-bb49-d130-604a-da1e11150ef3@linux.ibm.com \
--to=frankja@linux.ibm.com \
--cc=cohuck@redhat.com \
--cc=david@redhat.com \
--cc=imbrenda@linux.ibm.com \
--cc=kvm@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--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