Skip to content

Commit 215a681

Browse files
suomilewissean-jc
authored andcommitted
KVM: selftests: Add additional pages to the guest to accommodate ucall
Add additional pages to the guest to account for the number of pages the ucall headers need. The only reason things worked before is the ucall headers are fairly small. If they were ever to increase in size the guest could run out of memory. This is done in preparation for adding string formatting options to the guest through the ucall framework which increases the size of the ucall headers. Fixes: 426729b ("KVM: selftests: Add ucall pool based implementation") Signed-off-by: Aaron Lewis <aaronlewis@google.com> Link: https://lore.kernel.org/r/20230729003643.1053367-7-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent e511938 commit 215a681

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

tools/testing/selftests/kvm/include/ucall_common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ void *ucall_arch_get_ucall(struct kvm_vcpu *vcpu);
3434
void ucall(uint64_t cmd, int nargs, ...);
3535
uint64_t get_ucall(struct kvm_vcpu *vcpu, struct ucall *uc);
3636
void ucall_init(struct kvm_vm *vm, vm_paddr_t mmio_gpa);
37+
int ucall_nr_pages_required(uint64_t page_size);
3738

3839
/*
3940
* Perform userspace call without any associated data. This bare call avoids

tools/testing/selftests/kvm/lib/kvm_util.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ static uint64_t vm_nr_pages_required(enum vm_guest_mode mode,
312312
uint32_t nr_runnable_vcpus,
313313
uint64_t extra_mem_pages)
314314
{
315+
uint64_t page_size = vm_guest_mode_params[mode].page_size;
315316
uint64_t nr_pages;
316317

317318
TEST_ASSERT(nr_runnable_vcpus,
@@ -340,6 +341,9 @@ static uint64_t vm_nr_pages_required(enum vm_guest_mode mode,
340341
*/
341342
nr_pages += (nr_pages + extra_mem_pages) / PTES_PER_MIN_PAGE * 2;
342343

344+
/* Account for the number of pages needed by ucall. */
345+
nr_pages += ucall_nr_pages_required(page_size);
346+
343347
return vm_adjust_num_guest_pages(mode, nr_pages);
344348
}
345349

tools/testing/selftests/kvm/lib/ucall_common.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ struct ucall_header {
1111
struct ucall ucalls[KVM_MAX_VCPUS];
1212
};
1313

14+
int ucall_nr_pages_required(uint64_t page_size)
15+
{
16+
return align_up(sizeof(struct ucall_header), page_size) / page_size;
17+
}
18+
1419
/*
1520
* ucall_pool holds per-VM values (global data is duplicated by each VM), it
1621
* must not be accessed from host code.

0 commit comments

Comments
 (0)