From: Janis Schoetterl-Glausch <scgl@linux.ibm.com>
To: Christian Borntraeger <borntraeger@linux.ibm.com>,
Janosch Frank <frankja@linux.ibm.com>,
Claudio Imbrenda <imbrenda@linux.ibm.com>,
Shuah Khan <shuah@kernel.org>
Cc: Janis Schoetterl-Glausch <scgl@linux.ibm.com>,
Thomas Huth <thuth@redhat.com>,
David Hildenbrand <david@redhat.com>,
kvm@vger.kernel.org, linux-kselftest@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH v2 3/5] KVM: s390: selftests: Add named stages for memop test
Date: Tue, 8 Mar 2022 13:58:39 +0100 [thread overview]
Message-ID: <20220308125841.3271721-4-scgl@linux.ibm.com> (raw)
In-Reply-To: <20220308125841.3271721-1-scgl@linux.ibm.com>
The stages synchronize guest and host execution.
This helps the reader and constraits the execution of the test -- if the
observed staging differs from the expected the test fails.
Signed-off-by: Janis Schoetterl-Glausch <scgl@linux.ibm.com>
---
tools/testing/selftests/kvm/s390x/memop.c | 44 +++++++++++++++++------
1 file changed, 33 insertions(+), 11 deletions(-)
diff --git a/tools/testing/selftests/kvm/s390x/memop.c b/tools/testing/selftests/kvm/s390x/memop.c
index e2ad3d70bae4..88ce2d670ed5 100644
--- a/tools/testing/selftests/kvm/s390x/memop.c
+++ b/tools/testing/selftests/kvm/s390x/memop.c
@@ -218,10 +218,32 @@ static struct test_default test_default_init(void *guest_code)
return t;
}
+enum stage {
+ /* Synced state set by host, e.g. DAT */
+ STAGE_INITED,
+ /* Guest did nothing */
+ STAGE_IDLED,
+ /* Guest copied memory (locations up to test case) */
+ STAGE_COPIED,
+};
+
+#define HOST_SYNC(vcpu_p, stage) \
+({ \
+ struct test_vcpu __vcpu = (vcpu_p); \
+ struct ucall uc; \
+ int __stage = (stage); \
+ \
+ vcpu_run(__vcpu.vm, __vcpu.id); \
+ get_ucall(__vcpu.vm, __vcpu.id, &uc); \
+ ASSERT_EQ(uc.cmd, UCALL_SYNC); \
+ ASSERT_EQ(uc.args[1], __stage); \
+}) \
+
static void guest_copy(void)
{
+ GUEST_SYNC(STAGE_INITED);
memcpy(&mem2, &mem1, sizeof(mem2));
- GUEST_SYNC(0);
+ GUEST_SYNC(STAGE_COPIED);
}
static void test_copy(void)
@@ -232,16 +254,13 @@ static void test_copy(void)
for (i = 0; i < sizeof(mem1); i++)
mem1[i] = i * i + i;
+ HOST_SYNC(t.vcpu, STAGE_INITED);
+
/* Set the first array */
- MOP(t.vcpu, LOGICAL, WRITE, mem1, t.size,
- GADDR(addr_gva2gpa(t.kvm_vm, (uintptr_t)mem1)));
+ MOP(t.vcpu, LOGICAL, WRITE, mem1, t.size, GADDR_V(mem1));
/* Let the guest code copy the first array to the second */
- vcpu_run(t.kvm_vm, VCPU_ID);
- TEST_ASSERT(t.run->exit_reason == KVM_EXIT_S390_SIEIC,
- "Unexpected exit reason: %u (%s)\n",
- t.run->exit_reason,
- exit_reason_str(t.run->exit_reason));
+ HOST_SYNC(t.vcpu, STAGE_COPIED);
memset(mem2, 0xaa, sizeof(mem2));
@@ -256,8 +275,9 @@ static void test_copy(void)
static void guest_idle(void)
{
+ GUEST_SYNC(STAGE_INITED); /* for consistency's sake */
for (;;)
- GUEST_SYNC(0);
+ GUEST_SYNC(STAGE_IDLED);
}
static void test_errors(void)
@@ -265,6 +285,8 @@ static void test_errors(void)
struct test_default t = test_default_init(guest_idle);
int rv;
+ HOST_SYNC(t.vcpu, STAGE_INITED);
+
/* Bad size: */
rv = ERR_MOP(t.vcpu, LOGICAL, WRITE, mem1, -1, GADDR_V(mem1));
TEST_ASSERT(rv == -1 && errno == E2BIG, "ioctl allows insane sizes");
@@ -294,11 +316,11 @@ static void test_errors(void)
/* Bad access register: */
t.run->psw_mask &= ~(3UL << (63 - 17));
t.run->psw_mask |= 1UL << (63 - 17); /* Enable AR mode */
- vcpu_run(t.kvm_vm, VCPU_ID); /* To sync new state to SIE block */
+ HOST_SYNC(t.vcpu, STAGE_IDLED); /* To sync new state to SIE block */
rv = ERR_MOP(t.vcpu, LOGICAL, WRITE, mem1, t.size, GADDR_V(mem1), AR(17));
TEST_ASSERT(rv == -1 && errno == EINVAL, "ioctl allows ARs > 15");
t.run->psw_mask &= ~(3UL << (63 - 17)); /* Disable AR mode */
- vcpu_run(t.kvm_vm, VCPU_ID); /* Run to sync new state */
+ HOST_SYNC(t.vcpu, STAGE_IDLED); /* Run to sync new state */
/* Check that the SIDA calls are rejected for non-protected guests */
rv = ERR_MOP(t.vcpu, SIDA, READ, mem1, 8, GADDR(0), SIDA_OFFSET(0x1c0));
--
2.32.0
next prev parent reply other threads:[~2022-03-08 12:59 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-08 12:58 [PATCH RESEND v2 0/5] memop selftest for storage key checking Janis Schoetterl-Glausch
2022-03-08 12:58 ` [PATCH v2 1/5] KVM: s390: selftests: Split memop tests Janis Schoetterl-Glausch
2022-03-08 12:58 ` [PATCH v2 2/5] KVM: s390: selftests: Add macro as abstraction for MEM_OP Janis Schoetterl-Glausch
2022-03-08 12:58 ` Janis Schoetterl-Glausch [this message]
2022-03-08 12:58 ` [PATCH v2 4/5] KVM: s390: selftests: Add more copy memop tests Janis Schoetterl-Glausch
2022-03-08 12:58 ` [PATCH v2 5/5] KVM: s390: selftests: Add error " Janis Schoetterl-Glausch
2022-03-08 18:35 ` [PATCH RESEND v2 0/5] memop selftest for storage key checking Christian Borntraeger
2022-03-09 9:05 ` Christian Borntraeger
2022-03-09 10:43 ` Janis Schoetterl-Glausch
-- strict thread matches above, loose matches on Subject: below --
2022-02-11 18:22 [PATCH v4 10/10] KVM: s390: selftests: Test memops with storage keys Janis Schoetterl-Glausch
2022-02-25 15:53 ` [PATCH v2 0/5] memop selftest for storage key checking Janis Schoetterl-Glausch
2022-02-25 15:53 ` [PATCH v2 3/5] KVM: s390: selftests: Add named stages for memop test Janis Schoetterl-Glausch
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=20220308125841.3271721-4-scgl@linux.ibm.com \
--to=scgl@linux.ibm.com \
--cc=borntraeger@linux.ibm.com \
--cc=david@redhat.com \
--cc=frankja@linux.ibm.com \
--cc=imbrenda@linux.ibm.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=shuah@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