Skip to content

Commit c711596

Browse files
Janis Schoetterl-Glauschfrankjaa
authored andcommitted
KVM: s390: selftest: Test suppression indication on key prot exception
Check that suppression is not indicated on injection of a key checked protection exception caused by a memop after it already modified guest memory, as that violates the definition of suppression. Signed-off-by: Janis Schoetterl-Glausch <scgl@linux.ibm.com> Reviewed-by: Christian Borntraeger <borntraeger@linux.ibm.com> Link: https://lore.kernel.org/r/20220512131019.2594948-3-scgl@linux.ibm.com Signed-off-by: Christian Borntraeger <borntraeger@linux.ibm.com> Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
1 parent c783631 commit c711596

1 file changed

Lines changed: 45 additions & 1 deletion

File tree

  • tools/testing/selftests/kvm/s390x

tools/testing/selftests/kvm/s390x/memop.c

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include <string.h>
1111
#include <sys/ioctl.h>
1212

13+
#include <linux/bits.h>
14+
1315
#include "test_util.h"
1416
#include "kvm_util.h"
1517

@@ -194,6 +196,7 @@ static int err_memop_ioctl(struct test_vcpu vcpu, struct kvm_s390_mem_op *ksmo)
194196
#define SIDA_OFFSET(o) ._sida_offset = 1, .sida_offset = (o)
195197
#define AR(a) ._ar = 1, .ar = (a)
196198
#define KEY(a) .f_key = 1, .key = (a)
199+
#define INJECT .f_inject = 1
197200

198201
#define CHECK_N_DO(f, ...) ({ f(__VA_ARGS__, CHECK_ONLY); f(__VA_ARGS__); })
199202

@@ -430,9 +433,18 @@ static void test_copy_key_fetch_prot(void)
430433
TEST_ASSERT(rv == 4, "Should result in protection exception"); \
431434
})
432435

436+
static void guest_error_key(void)
437+
{
438+
GUEST_SYNC(STAGE_INITED);
439+
set_storage_key_range(mem1, PAGE_SIZE, 0x18);
440+
set_storage_key_range(mem1 + PAGE_SIZE, sizeof(mem1) - PAGE_SIZE, 0x98);
441+
GUEST_SYNC(STAGE_SKEYS_SET);
442+
GUEST_SYNC(STAGE_IDLED);
443+
}
444+
433445
static void test_errors_key(void)
434446
{
435-
struct test_default t = test_default_init(guest_copy_key_fetch_prot);
447+
struct test_default t = test_default_init(guest_error_key);
436448

437449
HOST_SYNC(t.vcpu, STAGE_INITED);
438450
HOST_SYNC(t.vcpu, STAGE_SKEYS_SET);
@@ -446,6 +458,37 @@ static void test_errors_key(void)
446458
kvm_vm_free(t.kvm_vm);
447459
}
448460

461+
static void test_termination(void)
462+
{
463+
struct test_default t = test_default_init(guest_error_key);
464+
uint64_t prefix;
465+
uint64_t teid;
466+
uint64_t teid_mask = BIT(63 - 56) | BIT(63 - 60) | BIT(63 - 61);
467+
uint64_t psw[2];
468+
469+
HOST_SYNC(t.vcpu, STAGE_INITED);
470+
HOST_SYNC(t.vcpu, STAGE_SKEYS_SET);
471+
472+
/* vcpu, mismatching keys after first page */
473+
ERR_PROT_MOP(t.vcpu, LOGICAL, WRITE, mem1, t.size, GADDR_V(mem1), KEY(1), INJECT);
474+
/*
475+
* The memop injected a program exception and the test needs to check the
476+
* Translation-Exception Identification (TEID). It is necessary to run
477+
* the guest in order to be able to read the TEID from guest memory.
478+
* Set the guest program new PSW, so the guest state is not clobbered.
479+
*/
480+
prefix = t.run->s.regs.prefix;
481+
psw[0] = t.run->psw_mask;
482+
psw[1] = t.run->psw_addr;
483+
MOP(t.vm, ABSOLUTE, WRITE, psw, sizeof(psw), GADDR(prefix + 464));
484+
HOST_SYNC(t.vcpu, STAGE_IDLED);
485+
MOP(t.vm, ABSOLUTE, READ, &teid, sizeof(teid), GADDR(prefix + 168));
486+
/* Bits 56, 60, 61 form a code, 0 being the only one allowing for termination */
487+
ASSERT_EQ(teid & teid_mask, 0);
488+
489+
kvm_vm_free(t.kvm_vm);
490+
}
491+
449492
static void test_errors_key_storage_prot_override(void)
450493
{
451494
struct test_default t = test_default_init(guest_copy_key_fetch_prot);
@@ -668,6 +711,7 @@ int main(int argc, char *argv[])
668711
test_copy_key_fetch_prot();
669712
test_copy_key_fetch_prot_override();
670713
test_errors_key();
714+
test_termination();
671715
test_errors_key_storage_prot_override();
672716
test_errors_key_fetch_prot_override_not_enabled();
673717
test_errors_key_fetch_prot_override_enabled();

0 commit comments

Comments
 (0)