summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/kvm/include/x86_64/kvm_util_arch.h
diff options
context:
space:
mode:
authorPeter Gonda <pgonda@google.com>2024-02-23 03:42:54 +0300
committerSean Christopherson <seanjc@google.com>2024-02-29 03:39:49 +0300
commitbe1bd4c5394ff7eb6f14aaf8005824ed1946bb82 (patch)
treea7c522307e18d941139c37b6f0ffd7d9c88dbe97 /tools/testing/selftests/kvm/include/x86_64/kvm_util_arch.h
parent31e00dae72fda939a084cda86b068ac9c302a2d3 (diff)
downloadlinux-be1bd4c5394ff7eb6f14aaf8005824ed1946bb82.tar.xz
KVM: selftests: Allow tagging protected memory in guest page tables
Add support for tagging and untagging guest physical address, e.g. to allow x86's SEV and TDX guests to embed shared vs. private information in the GPA. SEV (encryption, a.k.a. C-bit) and TDX (shared, a.k.a. S-bit) steal bits from the guest's physical address space that is consumed by the CPU metadata, i.e. effectively aliases the "real" GPA. Implement generic "tagging" so that the shared vs. private metadata can be managed by x86 without bleeding too many details into common code. Cc: Paolo Bonzini <pbonzini@redhat.com> Cc: Sean Christopherson <seanjc@google.com> Cc: Vishal Annapurve <vannapurve@google.com> Cc: Ackerly Tng <ackerleytng@google.com> cc: Andrew Jones <andrew.jones@linux.dev> Cc: Tom Lendacky <thomas.lendacky@amd.com> Cc: Michael Roth <michael.roth@amd.com> Tested-by: Carlos Bilbao <carlos.bilbao@amd.com> Originally-by: Michael Roth <michael.roth@amd.com> Signed-off-by: Peter Gonda <pgonda@google.com> Link: https://lore.kernel.org/r/20240223004258.3104051-8-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
Diffstat (limited to 'tools/testing/selftests/kvm/include/x86_64/kvm_util_arch.h')
-rw-r--r--tools/testing/selftests/kvm/include/x86_64/kvm_util_arch.h21
1 files changed, 21 insertions, 0 deletions
diff --git a/tools/testing/selftests/kvm/include/x86_64/kvm_util_arch.h b/tools/testing/selftests/kvm/include/x86_64/kvm_util_arch.h
new file mode 100644
index 000000000000..cfdf8c5e2671
--- /dev/null
+++ b/tools/testing/selftests/kvm/include/x86_64/kvm_util_arch.h
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef SELFTEST_KVM_UTIL_ARCH_H
+#define SELFTEST_KVM_UTIL_ARCH_H
+
+#include <stdbool.h>
+#include <stdint.h>
+
+struct kvm_vm_arch {
+ uint64_t c_bit;
+ uint64_t s_bit;
+};
+
+static inline bool __vm_arch_has_protected_memory(struct kvm_vm_arch *arch)
+{
+ return arch->c_bit || arch->s_bit;
+}
+
+#define vm_arch_has_protected_memory(vm) \
+ __vm_arch_has_protected_memory(&(vm)->arch)
+
+#endif // SELFTEST_KVM_UTIL_ARCH_H