[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20220830224259.412342-5-vannapurve@google.com>
Date: Tue, 30 Aug 2022 22:42:55 +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,
Vishal Annapurve <vannapurve@...gle.com>
Subject: [RFC V2 PATCH 4/8] selftests: kvm: sev: Support memslots with private memory
Introduce an additional helper API to create a SEV VM with private
memory memslots.
Signed-off-by: Vishal Annapurve <vannapurve@...gle.com>
---
tools/testing/selftests/kvm/include/x86_64/sev.h | 2 ++
tools/testing/selftests/kvm/lib/x86_64/sev.c | 15 ++++++++++++---
2 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/tools/testing/selftests/kvm/include/x86_64/sev.h b/tools/testing/selftests/kvm/include/x86_64/sev.h
index b6552ea1c716..628801707917 100644
--- a/tools/testing/selftests/kvm/include/x86_64/sev.h
+++ b/tools/testing/selftests/kvm/include/x86_64/sev.h
@@ -38,6 +38,8 @@ void kvm_sev_ioctl(struct sev_vm *sev, int cmd, void *data);
struct kvm_vm *sev_get_vm(struct sev_vm *sev);
uint8_t sev_get_enc_bit(struct sev_vm *sev);
+struct sev_vm *sev_vm_create_with_flags(uint32_t policy, uint64_t npages,
+ uint32_t memslot_flags);
struct sev_vm *sev_vm_create(uint32_t policy, uint64_t npages);
void sev_vm_free(struct sev_vm *sev);
void sev_vm_launch(struct sev_vm *sev);
diff --git a/tools/testing/selftests/kvm/lib/x86_64/sev.c b/tools/testing/selftests/kvm/lib/x86_64/sev.c
index 44b5ce5cd8db..6a329ea17f9f 100644
--- a/tools/testing/selftests/kvm/lib/x86_64/sev.c
+++ b/tools/testing/selftests/kvm/lib/x86_64/sev.c
@@ -171,7 +171,8 @@ void sev_vm_free(struct sev_vm *sev)
free(sev);
}
-struct sev_vm *sev_vm_create(uint32_t policy, uint64_t npages)
+struct sev_vm *sev_vm_create_with_flags(uint32_t policy, uint64_t npages,
+ uint32_t memslot_flags)
{
struct sev_vm *sev;
struct kvm_vm *vm;
@@ -188,9 +189,12 @@ struct sev_vm *sev_vm_create(uint32_t policy, uint64_t npages)
vm->vpages_mapped = sparsebit_alloc();
vm_set_memory_encryption(vm, true, true, sev->enc_bit);
pr_info("SEV cbit: %d\n", sev->enc_bit);
- vm_userspace_mem_region_add(vm, VM_MEM_SRC_ANONYMOUS, 0, 0, npages, 0);
- sev_register_user_region(sev, addr_gpa2hva(vm, 0),
+ vm_userspace_mem_region_add(vm, VM_MEM_SRC_ANONYMOUS, 0, 0, npages,
+ memslot_flags);
+ if (!(memslot_flags & KVM_MEM_PRIVATE)) {
+ sev_register_user_region(sev, addr_gpa2hva(vm, 0),
npages * vm->page_size);
+ }
pr_info("SEV guest created, policy: 0x%x, size: %lu KB\n",
sev->sev_policy, npages * vm->page_size / 1024);
@@ -198,6 +202,11 @@ struct sev_vm *sev_vm_create(uint32_t policy, uint64_t npages)
return sev;
}
+struct sev_vm *sev_vm_create(uint32_t policy, uint64_t npages)
+{
+ return sev_vm_create_with_flags(policy, npages, 0);
+}
+
void sev_vm_launch(struct sev_vm *sev)
{
struct kvm_sev_launch_start ksev_launch_start = {0};
--
2.37.2.672.g94769d06f0-goog
Powered by blists - more mailing lists