From: Peter Gonda <pgonda@google.com>
SEV-ES guests need additional pages allocated for their GHCBs. Add arch
specific function definition with __weak to allow for overriding for X86
specific SEV-ES functionality.
Cc: Vishal Annapurve <vannapurve@google.com>
Cc: Ackerley Tng <ackerleytng@google.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Claudio Imbrenda <imbrenda@linux.ibm.com>
Cc: Sean Christopherson <seanjc@google.com>
Cc: Carlos Bilbao <carlos.bilbao@amd.com>
Cc: Tom Lendacky <thomas.lendacky@amd.com>
Cc: Michael Roth <michael.roth@amd.com>
Cc: kvm@vger.kernel.org
Cc: linux-kselftest@vger.kernel.org
Signed-off-by: Peter Gonda <pgonda@google.com>
Signed-off-by: Neeraj Upadhyay <Neeraj.Upadhyay@amd.com>
---
tools/testing/selftests/kvm/include/kvm_util.h | 2 ++
tools/testing/selftests/kvm/lib/kvm_util.c | 16 ++++++++++++----
2 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/tools/testing/selftests/kvm/include/kvm_util.h b/tools/testing/selftests/kvm/include/kvm_util.h
index 23a506d7eca3..1a9764658eb9 100644
--- a/tools/testing/selftests/kvm/include/kvm_util.h
+++ b/tools/testing/selftests/kvm/include/kvm_util.h
@@ -268,6 +268,8 @@ int get_kvm_param_integer(const char *param);
int get_kvm_intel_param_integer(const char *param);
int get_kvm_amd_param_integer(const char *param);
+int kvm_arch_vm_additional_pages_required(struct vm_shape shape,
+ uint64_t page_size);
unsigned int kvm_check_cap(long cap);
static inline bool kvm_has_cap(long cap)
diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c
index c3f5142b0a54..a3b16793b2fd 100644
--- a/tools/testing/selftests/kvm/lib/kvm_util.c
+++ b/tools/testing/selftests/kvm/lib/kvm_util.c
@@ -391,11 +391,11 @@ struct kvm_vm *____vm_create(struct vm_shape shape)
return vm;
}
-static uint64_t vm_nr_pages_required(enum vm_guest_mode mode,
+static uint64_t vm_nr_pages_required(struct vm_shape shape,
uint32_t nr_runnable_vcpus,
uint64_t extra_mem_pages)
{
- uint64_t page_size = vm_guest_mode_params[mode].page_size;
+ uint64_t page_size = vm_guest_mode_params[shape.mode].page_size;
uint64_t nr_pages;
TEST_ASSERT(nr_runnable_vcpus,
@@ -427,7 +427,9 @@ static uint64_t vm_nr_pages_required(enum vm_guest_mode mode,
/* Account for the number of pages needed by ucall. */
nr_pages += ucall_nr_pages_required(page_size);
- return vm_adjust_num_guest_pages(mode, nr_pages);
+ nr_pages += kvm_arch_vm_additional_pages_required(shape, page_size);
+
+ return vm_adjust_num_guest_pages(shape.mode, nr_pages);
}
void kvm_set_files_rlimit(uint32_t nr_vcpus)
@@ -474,7 +476,7 @@ static bool is_guest_memfd_required(struct vm_shape shape)
struct kvm_vm *__vm_create(struct vm_shape shape, uint32_t nr_runnable_vcpus,
uint64_t nr_extra_pages)
{
- uint64_t nr_pages = vm_nr_pages_required(shape.mode, nr_runnable_vcpus,
+ uint64_t nr_pages = vm_nr_pages_required(shape, nr_runnable_vcpus,
nr_extra_pages);
struct userspace_mem_region *slot0;
struct kvm_vm *vm;
@@ -2334,6 +2336,12 @@ __weak void kvm_arch_vm_post_create(struct kvm_vm *vm)
{
}
+__weak int kvm_arch_vm_additional_pages_required(struct vm_shape shape,
+ uint64_t page_size)
+{
+ return 0;
+}
+
__weak void kvm_selftest_arch_init(void)
{
}
--
2.34.1