[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20221223001352.3873203-8-vannapurve@google.com>
Date: Fri, 23 Dec 2022 00:13:51 +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, vkuznets@...hat.com, wanpengli@...cent.com,
jmattson@...gle.com, joro@...tes.org, tglx@...utronix.de,
mingo@...hat.com, bp@...en8.de, dave.hansen@...ux.intel.com,
hpa@...or.com, shuah@...nel.org, yang.zhong@...el.com,
drjones@...hat.com, ricarkol@...gle.com, aaronlewis@...gle.com,
wei.w.wang@...el.com, kirill.shutemov@...ux.intel.com,
corbet@....net, hughd@...gle.com, jlayton@...nel.org,
bfields@...ldses.org, akpm@...ux-foundation.org,
chao.p.peng@...ux.intel.com, yu.c.zhang@...ux.intel.com,
jun.nakajima@...el.com, dave.hansen@...el.com,
michael.roth@....com, qperret@...gle.com, steven.price@....com,
ak@...ux.intel.com, david@...hat.com, luto@...nel.org,
vbabka@...e.cz, marcorr@...gle.com, erdemaktas@...gle.com,
pgonda@...gle.com, nikunj@....com, seanjc@...gle.com,
diviness@...gle.com, maz@...nel.org, dmatlack@...gle.com,
axelrasmussen@...gle.com, maciej.szmigiero@...cle.com,
mizhang@...gle.com, bgardon@...gle.com, ackerleytng@...gle.com,
Vishal Annapurve <vannapurve@...gle.com>
Subject: [V3 PATCH 7/8] KVM: selftests: private_mem_test: Add support for SEV VMs
Add support of executing private mem test with SEV VMs to allow
creating SEV VMs and make the guest code do page table updates in
case of executiong from SEV VM context.
Signed-off-by: Vishal Annapurve <vannapurve@...gle.com>
---
.../include/x86_64/private_mem_test_helper.h | 3 ++
.../kvm/lib/x86_64/private_mem_test_helper.c | 37 +++++++++++++++++--
2 files changed, 37 insertions(+), 3 deletions(-)
diff --git a/tools/testing/selftests/kvm/include/x86_64/private_mem_test_helper.h b/tools/testing/selftests/kvm/include/x86_64/private_mem_test_helper.h
index 4d32c025876c..e54870b72369 100644
--- a/tools/testing/selftests/kvm/include/x86_64/private_mem_test_helper.h
+++ b/tools/testing/selftests/kvm/include/x86_64/private_mem_test_helper.h
@@ -12,4 +12,7 @@
void execute_vm_with_private_test_mem(
enum vm_mem_backing_src_type test_mem_src);
+void execute_sev_vm_with_private_test_mem(
+ enum vm_mem_backing_src_type test_mem_src);
+
#endif /* SELFTEST_KVM_PRIVATE_MEM_TEST_HELPER_H */
diff --git a/tools/testing/selftests/kvm/lib/x86_64/private_mem_test_helper.c b/tools/testing/selftests/kvm/lib/x86_64/private_mem_test_helper.c
index 600bd21d1bb8..36a8b1ab1c74 100644
--- a/tools/testing/selftests/kvm/lib/x86_64/private_mem_test_helper.c
+++ b/tools/testing/selftests/kvm/lib/x86_64/private_mem_test_helper.c
@@ -22,6 +22,9 @@
#include <private_mem.h>
#include <private_mem_test_helper.h>
#include <processor.h>
+#include <sev.h>
+
+static bool is_guest_sev_vm;
#define TEST_AREA_SLOT 10
#define TEST_AREA_GPA 0xC0000000
@@ -104,6 +107,8 @@ static void guest_conv_test_fn(void)
GUEST_ASSERT(verify_test_area(test_area_base, TEST_MEM_DATA_PATTERN1,
TEST_MEM_DATA_PATTERN1));
+ if (is_guest_sev_vm)
+ guest_set_region_shared(guest_test_mem, guest_test_size);
kvm_hypercall_map_shared((uint64_t)guest_test_mem, guest_test_size);
populate_guest_test_mem(guest_test_mem, TEST_MEM_DATA_PATTERN2);
@@ -112,6 +117,9 @@ static void guest_conv_test_fn(void)
GUEST_ASSERT(verify_test_area(test_area_base, TEST_MEM_DATA_PATTERN1,
TEST_MEM_DATA_PATTERN5));
+ if (is_guest_sev_vm)
+ guest_set_region_private(guest_test_mem, guest_test_size);
+
kvm_hypercall_map_private((uint64_t)guest_test_mem, guest_test_size);
populate_guest_test_mem(guest_test_mem, TEST_MEM_DATA_PATTERN3);
@@ -170,14 +178,19 @@ static void host_conv_test_fn(struct kvm_vm *vm, struct kvm_vcpu *vcpu)
ASSERT_GUEST_DONE(vcpu);
}
-void execute_vm_with_private_test_mem(
- enum vm_mem_backing_src_type test_mem_src)
+static void execute_private_mem_test(enum vm_mem_backing_src_type test_mem_src,
+ bool is_sev_vm)
{
struct kvm_vm *vm;
struct kvm_enable_cap cap;
struct kvm_vcpu *vcpu;
- vm = vm_create_with_one_vcpu(&vcpu, guest_conv_test_fn);
+ if (is_sev_vm)
+ vm = sev_vm_init_with_one_vcpu(SEV_POLICY_NO_DBG,
+ guest_conv_test_fn, &vcpu);
+ else
+ vm = vm_create_with_one_vcpu(&vcpu, guest_conv_test_fn);
+ TEST_ASSERT(vm, "VM creation failed\n");
vm_check_cap(vm, KVM_CAP_EXIT_HYPERCALL);
cap.cap = KVM_CAP_EXIT_HYPERCALL;
@@ -191,7 +204,25 @@ void execute_vm_with_private_test_mem(
virt_map(vm, TEST_AREA_GPA, TEST_AREA_GPA, TEST_AREA_SIZE/vm->page_size);
+ if (is_sev_vm) {
+ is_guest_sev_vm = true;
+ sync_global_to_guest(vm, is_guest_sev_vm);
+ sev_vm_finalize(vm, SEV_POLICY_NO_DBG);
+ }
+
host_conv_test_fn(vm, vcpu);
kvm_vm_free(vm);
}
+
+void execute_vm_with_private_test_mem(
+ enum vm_mem_backing_src_type test_mem_src)
+{
+ execute_private_mem_test(test_mem_src, false);
+}
+
+void execute_sev_vm_with_private_test_mem(
+ enum vm_mem_backing_src_type test_mem_src)
+{
+ execute_private_mem_test(test_mem_src, true);
+}
--
2.39.0.314.g84b9a713c41-goog
Powered by blists - more mailing lists