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 04/10] kvm: arm64: selftests: use ucall_ops to define default ucall implementation
Date: Fri, 10 Dec 2021 10:46:14 -0600 [thread overview]
Message-ID: <20211210164620.11636-5-michael.roth@amd.com> (raw)
In-Reply-To: <20211210164620.11636-1-michael.roth@amd.com>
As with x86, switch the default ucall implementation to using the new
ucall_ops infrastructure. With this change ucall_init/ucall_uninit are
no longer arch-specific and can now be dropped in favor of the ones in
ucall_common.c.
Signed-off-by: Michael Roth <michael.roth@amd.com>
---
tools/testing/selftests/kvm/Makefile | 2 +-
.../selftests/kvm/include/aarch64/ucall.h | 18 ++++++++
.../testing/selftests/kvm/include/kvm_util.h | 2 +-
.../testing/selftests/kvm/lib/aarch64/ucall.c | 43 +++++++++----------
4 files changed, 40 insertions(+), 25 deletions(-)
create mode 100644 tools/testing/selftests/kvm/include/aarch64/ucall.h
diff --git a/tools/testing/selftests/kvm/Makefile b/tools/testing/selftests/kvm/Makefile
index 05bff4039890..2d4299961d0e 100644
--- a/tools/testing/selftests/kvm/Makefile
+++ b/tools/testing/selftests/kvm/Makefile
@@ -35,7 +35,7 @@ endif
LIBKVM = lib/assert.c lib/elf.c lib/io.c lib/kvm_util.c lib/rbtree.c lib/sparsebit.c lib/test_util.c lib/guest_modes.c lib/perf_test_util.c
LIBKVM_x86_64 = lib/x86_64/apic.c lib/x86_64/processor.c lib/x86_64/vmx.c lib/x86_64/svm.c lib/x86_64/ucall.c lib/x86_64/handlers.S lib/ucall_common.c
-LIBKVM_aarch64 = lib/aarch64/processor.c lib/aarch64/ucall.c lib/aarch64/handlers.S lib/aarch64/spinlock.c lib/aarch64/gic.c lib/aarch64/gic_v3.c lib/aarch64/vgic.c
+LIBKVM_aarch64 = lib/aarch64/processor.c lib/aarch64/ucall.c lib/aarch64/handlers.S lib/aarch64/spinlock.c lib/aarch64/gic.c lib/aarch64/gic_v3.c lib/aarch64/vgic.c lib/ucall_common.c
LIBKVM_s390x = lib/s390x/processor.c lib/s390x/ucall.c lib/s390x/diag318_test_handler.c
TEST_GEN_PROGS_x86_64 = x86_64/cr4_cpuid_sync_test
diff --git a/tools/testing/selftests/kvm/include/aarch64/ucall.h b/tools/testing/selftests/kvm/include/aarch64/ucall.h
new file mode 100644
index 000000000000..d3189d0a4d68
--- /dev/null
+++ b/tools/testing/selftests/kvm/include/aarch64/ucall.h
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Arch-specific ucall implementations.
+ *
+ * A ucall is a "hypercall to userspace".
+ *
+ * Copyright (C) 2021 Advanced Micro Devices
+ */
+#ifndef SELFTEST_KVM_UCALL_H
+#define SELFTEST_KVM_UCALL_H
+
+#include "ucall_common.h"
+
+extern const struct ucall_ops ucall_ops_mmio;
+
+extern const struct ucall_ops ucall_ops_default;
+
+#endif /* SELFTEST_KVM_UCALL_H */
diff --git a/tools/testing/selftests/kvm/include/kvm_util.h b/tools/testing/selftests/kvm/include/kvm_util.h
index 2701bf98c0db..16ec8c53cd81 100644
--- a/tools/testing/selftests/kvm/include/kvm_util.h
+++ b/tools/testing/selftests/kvm/include/kvm_util.h
@@ -14,7 +14,7 @@
* new header. Once all archs implement the new header the #include for
* ucall_common.h can be dropped.
*/
-#ifdef __x86_64__
+#if defined(__x86_64__) || defined (__aarch64__)
#include "ucall.h"
#else
#include "ucall_common.h"
diff --git a/tools/testing/selftests/kvm/lib/aarch64/ucall.c b/tools/testing/selftests/kvm/lib/aarch64/ucall.c
index e0b0164e9af8..ab052ab5d5de 100644
--- a/tools/testing/selftests/kvm/lib/aarch64/ucall.c
+++ b/tools/testing/selftests/kvm/lib/aarch64/ucall.c
@@ -1,11 +1,14 @@
// SPDX-License-Identifier: GPL-2.0
/*
- * ucall support. A ucall is a "hypercall to userspace".
+ * Arch-specific ucall implementations.
+ *
+ * A ucall is a "hypercall to userspace".
*
* Copyright (C) 2018, Red Hat, Inc.
*/
-#include "kvm_util.h"
+#include "kvm_util_base.h"
#include "../kvm_util_internal.h"
+#include "ucall.h"
static vm_vaddr_t *ucall_exit_mmio_addr;
@@ -22,7 +25,7 @@ static bool ucall_mmio_init(struct kvm_vm *vm, vm_paddr_t gpa)
return true;
}
-void ucall_init(struct kvm_vm *vm, void *arg)
+static void ucall_ops_mmio_init(struct kvm_vm *vm, void *arg)
{
vm_paddr_t gpa, start, end, step, offset;
unsigned int bits;
@@ -65,38 +68,22 @@ void ucall_init(struct kvm_vm *vm, void *arg)
TEST_FAIL("Can't find a ucall mmio address");
}
-void ucall_uninit(struct kvm_vm *vm)
+static void ucall_ops_mmio_uninit(struct kvm_vm *vm)
{
ucall_exit_mmio_addr = 0;
sync_global_to_guest(vm, ucall_exit_mmio_addr);
}
-void ucall(uint64_t cmd, int nargs, ...)
+static void ucall_ops_mmio_send_cmd(struct ucall *uc)
{
- struct ucall uc = {
- .cmd = cmd,
- };
- va_list va;
- int i;
-
- nargs = nargs <= UCALL_MAX_ARGS ? nargs : UCALL_MAX_ARGS;
-
- va_start(va, nargs);
- for (i = 0; i < nargs; ++i)
- uc.args[i] = va_arg(va, uint64_t);
- va_end(va);
-
- *ucall_exit_mmio_addr = (vm_vaddr_t)&uc;
+ *ucall_exit_mmio_addr = (vm_vaddr_t)uc;
}
-uint64_t get_ucall(struct kvm_vm *vm, uint32_t vcpu_id, struct ucall *uc)
+static uint64_t ucall_ops_mmio_recv_cmd(struct kvm_vm *vm, uint32_t vcpu_id, struct ucall *uc)
{
struct kvm_run *run = vcpu_state(vm, vcpu_id);
struct ucall ucall = {};
- if (uc)
- memset(uc, 0, sizeof(*uc));
-
if (run->exit_reason == KVM_EXIT_MMIO &&
run->mmio.phys_addr == (uint64_t)ucall_exit_mmio_addr) {
vm_vaddr_t gva;
@@ -113,3 +100,13 @@ uint64_t get_ucall(struct kvm_vm *vm, uint32_t vcpu_id, struct ucall *uc)
return ucall.cmd;
}
+
+const struct ucall_ops ucall_ops_mmio = {
+ .name = "MMIO",
+ .init = ucall_ops_mmio_init,
+ .uninit = ucall_ops_mmio_uninit,
+ .send_cmd = ucall_ops_mmio_send_cmd,
+ .recv_cmd = ucall_ops_mmio_recv_cmd,
+};
+
+const struct ucall_ops ucall_ops_default = ucall_ops_mmio;
--
2.25.1
next prev parent reply other threads:[~2021-12-10 16:49 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 ucall implementations 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 ` Michael Roth [this message]
2021-12-10 16:46 ` [PATCH RFC 05/10] kvm: s390: selftests: use ucall_ops to define default ucall implementation 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 ` [PATCH RFC 09/10] kvm: selftests: add GUEST_SHARED_* macros for shared ucall implementations Michael Roth
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-5-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