[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20221222230458.3828342-3-vannapurve@google.com>
Date: Thu, 22 Dec 2022 23:04:58 +0000
From: Vishal Annapurve <vannapurve@...gle.com>
To: x86@...nel.org, kvm@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-kselftest@...r.kernel.org
Cc: pbonzini@...hat.com, shuah@...nel.org, bgardon@...gle.com,
seanjc@...gle.com, oupton@...gle.com, peterx@...hat.com,
vkuznets@...hat.com, dmatlack@...gle.com, pgonda@...gle.com,
andrew.jones@...ux.dev, Vishal Annapurve <vannapurve@...gle.com>
Subject: [V3 PATCH 2/2] KVM: selftests: x86: Add native hypercall support
Add an API to execute hypercall as per the cpu type by checking the
underlying CPU. KVM emulates vmcall/vmmcall instruction by modifying
guest memory contents with hypercall instruction as per the cpu type.
Confidential VMs need to execute hypercall instruction without it being
emulated by KVM as KVM can not modify guest memory contents.
Signed-off-by: Vishal Annapurve <vannapurve@...gle.com>
---
.../selftests/kvm/include/x86_64/processor.h | 3 +++
.../selftests/kvm/lib/x86_64/processor.c | 18 ++++++++++++++++++
2 files changed, 21 insertions(+)
diff --git a/tools/testing/selftests/kvm/include/x86_64/processor.h b/tools/testing/selftests/kvm/include/x86_64/processor.h
index 4d5dd9a467e1..3617f83bb2e5 100644
--- a/tools/testing/selftests/kvm/include/x86_64/processor.h
+++ b/tools/testing/selftests/kvm/include/x86_64/processor.h
@@ -1039,6 +1039,9 @@ uint64_t *vm_get_page_table_entry(struct kvm_vm *vm, uint64_t vaddr);
uint64_t kvm_hypercall(uint64_t nr, uint64_t a0, uint64_t a1, uint64_t a2,
uint64_t a3);
+uint64_t kvm_native_hypercall(uint64_t nr, uint64_t a0, uint64_t a1, uint64_t a2,
+ uint64_t a3);
+
void __vm_xsave_require_permission(int bit, const char *name);
#define vm_xsave_require_permission(perm) \
diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c b/tools/testing/selftests/kvm/lib/x86_64/processor.c
index 1e93bb3cb058..429e55f2609f 100644
--- a/tools/testing/selftests/kvm/lib/x86_64/processor.c
+++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c
@@ -1202,6 +1202,24 @@ uint64_t kvm_hypercall(uint64_t nr, uint64_t a0, uint64_t a1, uint64_t a2,
return r;
}
+uint64_t kvm_native_hypercall(uint64_t nr, uint64_t a0, uint64_t a1, uint64_t a2,
+ uint64_t a3)
+{
+ uint64_t r;
+
+ if (is_amd_cpu()) {
+ asm volatile("vmmcall"
+ : "=a"(r)
+ : "a"(nr), "b"(a0), "c"(a1), "d"(a2), "S"(a3));
+ } else {
+ asm volatile("vmcall"
+ : "=a"(r)
+ : "a"(nr), "b"(a0), "c"(a1), "d"(a2), "S"(a3));
+ }
+
+ return r;
+}
+
const struct kvm_cpuid2 *kvm_get_supported_hv_cpuid(void)
{
static struct kvm_cpuid2 *cpuid;
--
2.39.0.314.g84b9a713c41-goog
Powered by blists - more mailing lists