From: Michael Roth <michael.roth@amd.com>
To: <linux-kselftest@vger.kernel.org>
Cc: <kvm@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<x86@kernel.org>, Nathan Tempelman <natet@google.com>,
Marc Orr <marcorr@google.com>,
"Steve Rutherford" <srutherford@google.com>,
Sean Christopherson <seanjc@google.com>,
Mingwei Zhang <mizhang@google.com>,
Brijesh Singh <brijesh.singh@amd.com>,
Tom Lendacky <thomas.lendacky@amd.com>,
Varad Gautam <varad.gautam@suse.com>,
Shuah Khan <shuah@kernel.org>,
Vitaly Kuznetsov <vkuznets@redhat.com>,
"David Woodhouse" <dwmw@amazon.co.uk>,
Ricardo Koller <ricarkol@google.com>,
"Jim Mattson" <jmattson@google.com>,
Joerg Roedel <joro@8bytes.org>,
"Thomas Gleixner" <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, "Borislav Petkov" <bp@alien8.de>,
"H . Peter Anvin" <hpa@zytor.com>,
"Christian Borntraeger" <borntraeger@linux.ibm.com>,
Janosch Frank <frankja@linux.ibm.com>,
David Hildenbrand <david@redhat.com>,
"Claudio Imbrenda" <imbrenda@linux.ibm.com>,
Marc Zyngier <maz@kernel.org>, James Morse <james.morse@arm.com>,
Alexandru Elisei <alexandru.elisei@arm.com>,
"Suzuki K Poulose" <suzuki.poulose@arm.com>,
<kvmarm@lists.cs.columbia.edu>
Subject: [PATCH RFC 09/10] kvm: selftests: add GUEST_SHARED_* macros for shared ucall implementations
Date: Fri, 10 Dec 2021 10:46:19 -0600 [thread overview]
Message-ID: <20211210164620.11636-10-michael.roth@amd.com> (raw)
In-Reply-To: <20211210164620.11636-1-michael.roth@amd.com>
Introduce GUEST_SHARED_* macros, which are mostly analogous to existing
GUEST_SYNC/GUEST_ASSERT/etc macros used to simplify guest code that
uses ucall for host/guest synchronization.
There are also some new CHECK_GUEST_SHARED_* macros intended to provide
similar helpers in the host code that can pair directly with the guest
versions.
Signed-off-by: Michael Roth <michael.roth@amd.com>
---
.../selftests/kvm/include/ucall_common.h | 68 +++++++++++++++++++
1 file changed, 68 insertions(+)
diff --git a/tools/testing/selftests/kvm/include/ucall_common.h b/tools/testing/selftests/kvm/include/ucall_common.h
index ae0e8eec9734..b9b220dbd6c3 100644
--- a/tools/testing/selftests/kvm/include/ucall_common.h
+++ b/tools/testing/selftests/kvm/include/ucall_common.h
@@ -48,6 +48,7 @@ vm_vaddr_t ucall_shared_alloc(struct kvm_vm *vm, int count);
void ucall_shared(struct ucall *uc, uint64_t cmd, int nargs, ...);
uint64_t get_ucall_shared(struct kvm_vm *vm, uint32_t vcpu_id, struct ucall *uc);
+/* Helpers for host/guest synchronization using ucall_shared */
#define GUEST_SYNC_ARGS(stage, arg1, arg2, arg3, arg4) \
ucall(UCALL_SYNC, 6, "hello", stage, arg1, arg2, arg3, arg4)
#define GUEST_SYNC(stage) ucall(UCALL_SYNC, 2, "hello", stage)
@@ -76,4 +77,71 @@ uint64_t get_ucall_shared(struct kvm_vm *vm, uint32_t vcpu_id, struct ucall *uc)
#define GUEST_ASSERT_EQ(a, b) __GUEST_ASSERT((a) == (b), #a " == " #b, 2, a, b)
+/* Helper macros for ucall synchronization via shared memory/ucall struct. */
+#define GUEST_SHARED_SYNC_ARGS(uc, stage, arg1, arg2, arg3, arg4) \
+ ucall_shared(uc, UCALL_SYNC, 6, "hello", stage, arg1, arg2, arg3, arg4)
+#define GUEST_SHARED_SYNC(uc, stage) \
+ ucall_shared(uc, UCALL_SYNC, 2, "hello", stage)
+#define GUEST_SHARED_DONE(uc) \
+ ucall_shared(uc, UCALL_DONE, 0)
+#define __GUEST_SHARED_ASSERT(uc, _condition, _condstr, _nargs, _args...) do { \
+ if (!(_condition)) \
+ ucall_shared(uc, UCALL_ABORT, 2 + _nargs, \
+ "Failed guest assert: " \
+ _condstr, __LINE__, _args); \
+} while (0)
+
+#define GUEST_SHARED_ASSERT(uc, _condition) \
+ __GUEST_SHARED_ASSERT(uc, _condition, #_condition, 0, 0)
+
+#define GUEST_SHARED_ASSERT_1(uc, _condition, arg1) \
+ __GUEST_SHARED_ASSERT(uc, _condition, #_condition, 1, (arg1))
+
+#define GUEST_SHARED_ASSERT_2(uc, _condition, arg1, arg2) \
+ __GUEST_SHARED_ASSERT(uc, _condition, #_condition, 2, (arg1), (arg2))
+
+#define GUEST_SHARED_ASSERT_3(uc, _condition, arg1, arg2, arg3) \
+ __GUEST_SHARED_ASSERT(uc, _condition, #_condition, 3, (arg1), (arg2), (arg3))
+
+#define GUEST_SHARED_ASSERT_4(uc, _condition, arg1, arg2, arg3, arg4) \
+ __GUEST_SHARED_ASSERT(uc, _condition, #_condition, 4, (arg1), (arg2), (arg3), (arg4))
+
+#define GUEST_SHARED_ASSERT_EQ(uc, a, b) \
+ __GUEST_SHARED_ASSERT(uc, (a) == (b), #a " == " #b, 2, a, b)
+
+#define __CHECK_SHARED_STATE(uc, uc_cmd, uc_cmd_expected) do { \
+ if (uc_cmd != uc_cmd_expected) { \
+ if (uc_cmd == UCALL_ABORT) \
+ TEST_FAIL("Unexpected guest abort: \"%s\" at %s:%ld", \
+ (const char *)uc->args[0], __FILE__, \
+ uc->args[1]); \
+ else \
+ TEST_FAIL("Unexpected ucall command/state: %" PRIu64, \
+ uc_cmd); \
+ } \
+} while (0)
+
+#define CHECK_SHARED_SYNC(vm, vcpu_id, uc, stage) do { \
+ uint64_t uc_cmd = get_ucall_shared(vm, vcpu_id, uc); \
+ TEST_ASSERT(uc_cmd == UCALL_SYNC, \
+ "Unexpected ucall command/state: %" PRIu64, uc_cmd); \
+ TEST_ASSERT(!strcmp((char *)uc->args[0], "hello"), \
+ "Invalid ucall signature argument."); \
+ TEST_ASSERT(uc->args[1] == stage, \
+ "Invalid ucall sync stage: %" PRIu64, uc->args[1]); \
+} while (0)
+
+#define CHECK_SHARED_DONE(vm, vcpu_id, uc) do { \
+ uint64_t uc_cmd = get_ucall_shared(vm, vcpu_id, uc); \
+ __CHECK_SHARED_STATE(uc, uc_cmd, UCALL_DONE); \
+ TEST_ASSERT(uc_cmd == UCALL_DONE, \
+ "Unexpected ucall command/state: %" PRIu64, uc_cmd); \
+} while (0)
+
+#define CHECK_SHARED_ABORT(vm, vcpu_id, uc) do { \
+ uint64_t uc_cmd = get_ucall_shared(vm, vcpu_id, uc); \
+ TEST_ASSERT(uc_cmd == UCALL_ABORT, \
+ "Unexpected ucall command/state: %" PRIu64, uc_cmd); \
+} while (0)
+
#endif /* SELFTEST_KVM_UCALL_COMMON_H */
--
2.25.1
next prev parent reply other threads:[~2021-12-10 16:47 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-10 16:46 [RFC PATCH 00/10] KVM: selftests: Add support for test-selectable " Michael Roth
2021-12-10 16:46 ` [PATCH RFC 01/10] kvm: selftests: move base kvm_util.h declarations to kvm_util_base.h Michael Roth
2021-12-10 16:46 ` [PATCH RFC 02/10] kvm: selftests: move ucall declarations into ucall_common.h Michael Roth
2021-12-25 9:11 ` Andrew Jones
2021-12-10 16:46 ` [PATCH RFC 03/10] kvm: selftests: introduce ucall_ops for test/arch-specific ucall implementations Michael Roth
2021-12-10 16:46 ` [PATCH RFC 04/10] kvm: arm64: selftests: use ucall_ops to define default ucall implementation Michael Roth
2021-12-10 16:46 ` [PATCH RFC 05/10] kvm: s390: " Michael Roth
2021-12-10 16:46 ` [PATCH RFC 06/10] kvm: selftests: add ucall interfaces based around shared memory Michael Roth
2021-12-10 16:46 ` [PATCH RFC 07/10] kvm: selftests: add ucall_shared ops for PIO Michael Roth
2021-12-10 16:46 ` [PATCH RFC 08/10] kvm: selftests: introduce ucall implementation based on halt instructions Michael Roth
2021-12-10 16:46 ` Michael Roth [this message]
2021-12-10 16:46 ` [PATCH RFC 10/10] kvm: selftests: add ucall_test to test various ucall functionality Michael Roth
2021-12-22 14:46 ` [RFC PATCH 00/10] KVM: selftests: Add support for test-selectable ucall implementations Paolo Bonzini
2021-12-30 21:11 ` Sean Christopherson
2022-01-04 23:35 ` Michael Roth
2022-01-05 0:17 ` Sean Christopherson
2022-01-05 17:02 ` Michael Roth
2022-01-05 17:43 ` Sean Christopherson
2022-01-05 19:11 ` Michael Roth
2022-01-05 19:40 ` Sean Christopherson
2022-01-05 21:35 ` Michael Roth
2022-01-05 22:02 ` Sean Christopherson
2022-01-05 22:32 ` Michael Roth
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=20211210164620.11636-10-michael.roth@amd.com \
--to=michael.roth@amd.com \
--cc=alexandru.elisei@arm.com \
--cc=borntraeger@linux.ibm.com \
--cc=bp@alien8.de \
--cc=brijesh.singh@amd.com \
--cc=david@redhat.com \
--cc=dwmw@amazon.co.uk \
--cc=frankja@linux.ibm.com \
--cc=hpa@zytor.com \
--cc=imbrenda@linux.ibm.com \
--cc=james.morse@arm.com \
--cc=jmattson@google.com \
--cc=joro@8bytes.org \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.cs.columbia.edu \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=marcorr@google.com \
--cc=maz@kernel.org \
--cc=mingo@redhat.com \
--cc=mizhang@google.com \
--cc=natet@google.com \
--cc=ricarkol@google.com \
--cc=seanjc@google.com \
--cc=shuah@kernel.org \
--cc=srutherford@google.com \
--cc=suzuki.poulose@arm.com \
--cc=tglx@linutronix.de \
--cc=thomas.lendacky@amd.com \
--cc=varad.gautam@suse.com \
--cc=vkuznets@redhat.com \
--cc=x86@kernel.org \
/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
Powered by JetHome