From: Janis Schoetterl-Glausch <scgl@linux.ibm.com>
To: Claudio Imbrenda <imbrenda@linux.ibm.com>
Cc: Thomas Huth <thuth@redhat.com>,
Janosch Frank <frankja@linux.ibm.com>,
David Hildenbrand <david@redhat.com>,
kvm@vger.kernel.org, linux-s390@vger.kernel.org
Subject: Re: [kvm-unit-tests PATCH] s390x: Test effect of storage keys on some instructions
Date: Thu, 24 Feb 2022 16:55:14 +0100 [thread overview]
Message-ID: <0616bdcb-a17a-6628-a069-f40706f9f40c@linux.ibm.com> (raw)
In-Reply-To: <20220224153041.5e99c0b3@p-imbrenda>
On 2/24/22 15:30, Claudio Imbrenda wrote:
> On Thu, 24 Feb 2022 12:09:50 +0100
> Janis Schoetterl-Glausch <scgl@linux.ibm.com> wrote:
>
>> Some instructions are emulated by KVM. Test that KVM correctly emulates
>> storage key checking for two of those instructions (STORE CPU ADDRESS,
>> SET PREFIX).
>> Test success and error conditions, including coverage of storage and
>> fetch protection override.
>> Also add test for TEST PROTECTION, even if that instruction will not be
>> emulated by KVM under normal conditions.
>>
>> Signed-off-by: Janis Schoetterl-Glausch <scgl@linux.ibm.com>
>> ---
>>
>> *entry_0_p = entry_pagebuf;
>>
>> I'm wondering if we need a barrier here, or would if set_prefix_key_1
>> wasn't made up of an asm volatile. But the mmu code seems to not have a
>> barrier in the equivalent code, so maybe it's never needed.
>>
>> set_prefix_key_1(0);
>>
>> lib/s390x/asm/arch_def.h | 20 ++---
>> s390x/skey.c | 169 +++++++++++++++++++++++++++++++++++++++
>> 2 files changed, 180 insertions(+), 9 deletions(-)
>>
[...]
>> diff --git a/s390x/skey.c b/s390x/skey.c
>> index 58a55436..6ae2d026 100644
>> --- a/s390x/skey.c
>> +++ b/s390x/skey.c
>> @@ -10,7 +10,10 @@
>> #include <libcflat.h>
>> #include <asm/asm-offsets.h>
>> #include <asm/interrupt.h>
>> +#include <vmalloc.h>
>> +#include <mmu.h>
>> #include <asm/page.h>
>> +#include <asm/pgtable.h>
>> #include <asm/facility.h>
>> #include <asm/mem.h>
>>
>> @@ -147,6 +150,167 @@ static void test_invalid_address(void)
>> report_prefix_pop();
>> }
>>
>> +static void test_test_protection(void)
>> +{
>> + unsigned long addr = (unsigned long)pagebuf;
>> +
>> + report_prefix_push("TPROT");
>> + set_storage_key(pagebuf, 0x10, 0);
>> + report(tprot(addr, 0) == 0, "access key 0 -> no protection");
>> + report(tprot(addr, 1) == 0, "access key matches -> no protection");
>> + report(tprot(addr, 2) == 1, "access key mismatches, no fetch protection -> store protection");
>> + set_storage_key(pagebuf, 0x18, 0);
>> + report(tprot(addr, 2) == 2, "access key mismatches, fetch protection -> fetch & store protection");
>> + report_prefix_pop();
>
> is there a reason why you don't set the storage key back to 0 once
> you're done?
None, other than it not being necessary, but I like the idea.
>
>> +}
>> +
>> +static void store_cpu_address_key_1(uint16_t *out)
>> +{
>> + asm volatile (
>> + "spka 0x10(0)\n\t"
>> + "stap %0\n\t"
>> + "spka 0(0)\n"
>> + : "=Q" (*out)
>> + );
>> +}
>> +
>> +static void test_store_cpu_address(void)
>> +{
>> + uint16_t *out = (uint16_t *)pagebuf;
>> + uint16_t cpu_addr;
>> +
>> + asm ("stap %0" : "=Q" (cpu_addr));
>> +
>> + report_prefix_push("STORE CPU ADDRESS, zero key");
>> + set_storage_key(pagebuf, 0x20, 0);
>> + *out = 0xbeef;
>> + asm ("stap %0" : "=Q" (*out));
>> + report(*out == cpu_addr, "store occurred");
>> + report_prefix_pop();
>> +
>> + report_prefix_push("STORE CPU ADDRESS, matching key");
>> + set_storage_key(pagebuf, 0x10, 0);
>> + *out = 0xbeef;
>> + store_cpu_address_key_1(out);
>> + report(*out == cpu_addr, "store occurred");
>> + report_prefix_pop();
>> +
>> + report_prefix_push("STORE CPU ADDRESS, mismatching key");
>> + set_storage_key(pagebuf, 0x20, 0);
>> + expect_pgm_int();
>> + store_cpu_address_key_1(out);
>> + check_pgm_int_code(PGM_INT_CODE_PROTECTION);
>
> for completeness, maybe also check that nothing gets stored?
Can do.
>
>> + report_prefix_pop();
>> +
>> + ctl_set_bit(0, CTL0_STORAGE_PROTECTION_OVERRIDE);
>> +
>> + report_prefix_push("STORE CPU ADDRESS, storage-protection override, invalid key");
>> + set_storage_key(pagebuf, 0x20, 0);
>> + expect_pgm_int();
>> + store_cpu_address_key_1(out);
>> + check_pgm_int_code(PGM_INT_CODE_PROTECTION);
>
> same here
>
[...]
prev parent reply other threads:[~2022-02-24 15:55 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-24 11:09 [kvm-unit-tests PATCH] s390x: Test effect of storage keys on some instructions Janis Schoetterl-Glausch
2022-02-24 14:30 ` Claudio Imbrenda
2022-02-24 15:55 ` Janis Schoetterl-Glausch [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=0616bdcb-a17a-6628-a069-f40706f9f40c@linux.ibm.com \
--to=scgl@linux.ibm.com \
--cc=david@redhat.com \
--cc=frankja@linux.ibm.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