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, 10 Jul 2023 17:05:35 +0200 [thread overview]
Message-ID: <76daa0d8-829d-2d48-4d70-92097518d565@linux.ibm.com> (raw)
In-Reply-To: <168899937501.42553.5805213823249646110@t14-nrb>
On 7/10/23 16:29, Nico Boehr wrote:
> Quoting Janosch Frank (2023-06-05 11:57:58)
> [...]
>>> diff --git a/s390x/sie-dat.c b/s390x/sie-dat.c
>>> new file mode 100644
>>> index 000000000000..c490a2aa825c
> [...]
>>> +#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.
>
> Yep, thanks, I cleaned up the includes a bit.
>
> [...]
>>> +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.
>
> Which patch are we talking about? pv_icptdata_check_diag()?
>
> Note that this is not a PV test, so I guess it's not applicable here?
Ah right, we could extend that but for one use this should be fine.
Let's see if there'll be more SIE tests that need this before building a
a full intercept check lib.
Could you lower-case the 0xFF00 when you re-spin?
>
>> Not every exit needs to be a report.
>> Some should rather be asserts() or report_info()s.
>
> Yeah, I have made report()s where it doesn't make sense to continue assert()s
>
>>> + 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...
>
> I am a bit confused but I *guess* you wanted me to move the declaration of
> expected_val to the beginning of the function?
>
Personally I'm not a big fan of declaring variables in the lower
function body, they are way too easy to overlook.
I dimly remember there being a rule but when I used a few minutes to
look for it I couldn't find it anymore. Hmmmm, maybe I'm getting old.
> [...]
>>> 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.
>
> A bunch of other tests do similar things, so I'll write a TODO and tackle it in
> a seperate series.
Thanks :)
>
> [...]
>>> +
>>> +__attribute__((section(".text"))) int main(void)
>>
>> The attribute shouldn't be needed anymore.
>
> OK, removed.
>
> [...]
>>> +{
>>> + 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?
>
> Because it's a suitable unsigned type for use as an array index.
>
> What should it be instead?
I would have used a standard uint type but to be fair this doesn't kill
me either.
prev parent reply other threads:[~2023-07-10 15:06 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
2023-07-10 14:29 ` Nico Boehr
2023-07-10 15:05 ` Janosch Frank [this message]
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=76daa0d8-829d-2d48-4d70-92097518d565@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