KVM: selftests: fix steal_time for arm64 with host page size > 4K
PATCH v2 1/1 KVM: selftests: fix steal_time for arm64 with host page size > 4K
Fix the following failure when running with 16K host page size:
==== Test Assertion Failure ====
lib/kvm_util.c:991: vm_adjust_num_guest_pages(vm->mode, npages) == npages pid=873 tid=873 errno=0 - Success
1 0x0000000000405a27: vm_mem_add at kvm_util.c:991
2 0x000000000040241f: check_steal_time_uapi at steal_time.c:223 (discriminator 7)
3 (inlined by) main at steal_time.c:539 (discriminator 7)
4 0x00007fff8b57af3b: ?? ??:0
5 0x00007fff8b57b007: ?? ??:0
6 0x0000000000402b6f: _start at ??:?Number of guest pages is not compatible with the host. Try npages=4
--- tools/testing/selftests/kvm/steal_time.c | 30 ++++++++++++++++-------- 1 file changed, 20 insertions(+), 10 deletions(-)
tools/testing/selftests/kvm/steal_time.c +20 -10
@@ -27,6 +27,9 @@static void *st_gva[NR_VCPUS ];static u64 guest_stolen_time[NR_VCPUS ]; +static struct kvm_vm *vm_create_steal_time (u32 nr_vcpus,void *guest_code, +struct kvm_vcpu *vcpus[]); +#if defined(__x86_64__)/* steal_time must have 64-byte alignment */
@@ -210,17 +213,14 @@ static void check_steal_time_uapi(void)u64 st_ipa;int ret; - vm =vm_create_with_one_vcpu (&vcpu,NULL ); -struct kvm_device_attr dev = { .group =KVM_ARM_VCPU_PVTIME_CTRL , .attr =KVM_ARM_VCPU_PVTIME_IPA , .addr = (u64)&st_ipa, }; + vm =vm_create_steal_time (1 ,NULL , &vcpu);vcpu_ioctl (vcpu,KVM_HAS_DEVICE_ATTR , &dev); -vm_userspace_mem_region_add (vm,VM_MEM_SRC_ANONYMOUS ,ST_GPA_BASE ,1 ,1 ,0 ); -virt_map (vm,ST_GPA_BASE ,ST_GPA_BASE ,1 ); st_ipa = (ulong )ST_GPA_BASE |1 ; ret =__vcpu_ioctl (vcpu,KVM_SET_DEVICE_ATTR , &dev);
@@ -500,13 +500,27 @@ static void run_vcpu(struct kvm_vcpu *vcpu) } } +static struct kvm_vm *vm_create_steal_time (u32 nr_vcpus,void *guest_code, +struct kvm_vcpu *vcpus[]) +{ +unsigned int gpages; +struct kvm_vm *vm; + +/* Create a VM and an identity mapped memslot for the steal time structure */ + vm =vm_create_with_vcpus (nr_vcpus, guest_code, vcpus); + gpages =vm_calc_num_guest_pages (VM_MODE_DEFAULT ,STEAL_TIME_SIZE * nr_vcpus); +vm_userspace_mem_region_add (vm,VM_MEM_SRC_ANONYMOUS ,ST_GPA_BASE ,1 , gpages,0 ); +virt_map (vm,ST_GPA_BASE ,ST_GPA_BASE , gpages); + +return vm; +} +int main (int ac,char **av) {struct kvm_vcpu *vcpus[NR_VCPUS ];struct kvm_vm *vm;pthread_t thread;cpu_set_t cpuset; -unsigned int gpages;long stolen_time;long run_delay;bool verbose;
@@ -517,11 +531,7 @@ int main(int ac, char **av)/* Set CPU affinity so we can force preemption of the VCPU */ cpu =pin_self_to_any_cpu (); -/* Create a VM and an identity mapped memslot for the steal time structure */ - vm =vm_create_with_vcpus (NR_VCPUS , guest_code, vcpus); - gpages =vm_calc_num_guest_pages (VM_MODE_DEFAULT ,STEAL_TIME_SIZE *NR_VCPUS ); -vm_userspace_mem_region_add (vm,VM_MEM_SRC_ANONYMOUS ,ST_GPA_BASE ,1 , gpages,0 ); -virt_map (vm,ST_GPA_BASE ,ST_GPA_BASE , gpages); + vm =vm_create_steal_time (NR_VCPUS , guest_code, vcpus);ksft_print_header ();TEST_REQUIRE (is_steal_time_supported (vcpus[0 ]));
Signature · 1 line
2.55.0
Quoted 12 lines · Sebastian Ott
Fix the following failure when running with 16K host page size:
==== Test Assertion Failure ====
lib/kvm_util.c:991:vm_adjust_num_guest_pages(vm->mode, npages)== npages pid=873 tid=873 errno=0 - Success1 0x0000000000405a27: vm_mem_add at kvm_util.c:991 2 0x000000000040241f: check_steal_time_uapi at steal_time.c:223 (discriminator 7) 3 (inlined by) main at steal_time.c:539 (discriminator 7) 4 0x00007fff8b57af3b: ?? ??:0 5 0x00007fff8b57b007: ?? ??:0 6 0x0000000000402b6f: _start at ??:?Number of guest pages is not compatible with the host. Try npages=4
Quoted 7 lines
Fixes fc240715fc50 ("KVM: selftests: arm64: Fix steal_time test after UAPI refactoring")Reported-by Zenghui Yu <[email protected]>Signed-off-by Sebastian Ott <[email protected]>--- tools/testing/selftests/kvm/steal_time.c | 30 ++++++++++++++++-------- 1 file changed, 20 insertions(+), 10 deletions(-)
Thanks,
Zenghui
Quoted 10 lines · Sebastian Ott
Fix the following failure when running with 16K host page size:
==== Test Assertion Failure ====
lib/kvm_util.c:991:vm_adjust_num_guest_pages(vm->mode, npages)== npages pid=873 tid=873 errno=0 - Success1 0x0000000000405a27: vm_mem_add at kvm_util.c:991 2 0x000000000040241f: check_steal_time_uapi at steal_time.c:223 (discriminator 7) 3 (inlined by) main at steal_time.c:539 (discriminator 7) 4 0x00007fff8b57af3b: ?? ??:0 5 0x00007fff8b57b007: ?? ??:0 6 0x0000000000402b6f: _start at ??:?
Quoted 3 lines
Number of guest pages is not compatible with the host. Try npages=4
[...]
Applied to fixes, thanks!
[1/1] KVM: selftests: fix steal_time for arm64 with host page size > 4K
https://git.kernel.org/kvmarm/kvmarm/c/96e6757cb067
--
Best,
Oliver