Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

KVM: selftests: Share common API documentation

Move function documentation comment blocks to the header files in
order to avoid duplicating them for each architecture. While at
it clean up and fix up the comment blocks.

Signed-off-by: Andrew Jones <drjones@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

authored by

Andrew Jones and committed by
Paolo Bonzini
42593624 1914f624

+188 -249
+98 -2
tools/testing/selftests/kvm/include/kvm_util.h
··· 16 16 #include "sparsebit.h" 17 17 18 18 19 - /* Callers of kvm_util only have an incomplete/opaque description of the 19 + /* 20 + * Callers of kvm_util only have an incomplete/opaque description of the 20 21 * structure kvm_util is using to maintain the state of a VM. 21 22 */ 22 23 struct kvm_vm; ··· 79 78 uint32_t data_memslot, uint32_t pgd_memslot); 80 79 81 80 void vm_dump(FILE *stream, struct kvm_vm *vm, uint8_t indent); 81 + 82 + /* 83 + * VM VCPU Dump 84 + * 85 + * Input Args: 86 + * stream - Output FILE stream 87 + * vm - Virtual Machine 88 + * vcpuid - VCPU ID 89 + * indent - Left margin indent amount 90 + * 91 + * Output Args: None 92 + * 93 + * Return: None 94 + * 95 + * Dumps the current state of the VCPU specified by @vcpuid, within the VM 96 + * given by @vm, to the FILE stream given by @stream. 97 + */ 82 98 void vcpu_dump(FILE *stream, struct kvm_vm *vm, uint32_t vcpuid, 83 99 uint8_t indent); 84 100 ··· 121 103 void *addr_gpa2hva(struct kvm_vm *vm, vm_paddr_t gpa); 122 104 void *addr_gva2hva(struct kvm_vm *vm, vm_vaddr_t gva); 123 105 vm_paddr_t addr_hva2gpa(struct kvm_vm *vm, void *hva); 106 + 107 + /* 108 + * Address Guest Virtual to Guest Physical 109 + * 110 + * Input Args: 111 + * vm - Virtual Machine 112 + * gva - VM virtual address 113 + * 114 + * Output Args: None 115 + * 116 + * Return: 117 + * Equivalent VM physical address 118 + * 119 + * Returns the VM physical address of the translated VM virtual 120 + * address given by @gva. 121 + */ 124 122 vm_paddr_t addr_gva2gpa(struct kvm_vm *vm, vm_vaddr_t gva); 125 123 126 124 struct kvm_run *vcpu_state(struct kvm_vm *vm, uint32_t vcpuid); ··· 147 113 struct kvm_mp_state *mp_state); 148 114 void vcpu_regs_get(struct kvm_vm *vm, uint32_t vcpuid, struct kvm_regs *regs); 149 115 void vcpu_regs_set(struct kvm_vm *vm, uint32_t vcpuid, struct kvm_regs *regs); 116 + 117 + /* 118 + * VM VCPU Args Set 119 + * 120 + * Input Args: 121 + * vm - Virtual Machine 122 + * vcpuid - VCPU ID 123 + * num - number of arguments 124 + * ... - arguments, each of type uint64_t 125 + * 126 + * Output Args: None 127 + * 128 + * Return: None 129 + * 130 + * Sets the first @num function input registers of the VCPU with @vcpuid, 131 + * per the C calling convention of the architecture, to the values given 132 + * as variable args. Each of the variable args is expected to be of type 133 + * uint64_t. The maximum @num can be is specific to the architecture. 134 + */ 150 135 void vcpu_args_set(struct kvm_vm *vm, uint32_t vcpuid, unsigned int num, ...); 136 + 151 137 void vcpu_sregs_get(struct kvm_vm *vm, uint32_t vcpuid, 152 138 struct kvm_sregs *sregs); 153 139 void vcpu_sregs_set(struct kvm_vm *vm, uint32_t vcpuid, ··· 196 142 const char *exit_reason_str(unsigned int exit_reason); 197 143 198 144 void virt_pgd_alloc(struct kvm_vm *vm, uint32_t pgd_memslot); 145 + 146 + /* 147 + * VM Virtual Page Map 148 + * 149 + * Input Args: 150 + * vm - Virtual Machine 151 + * vaddr - VM Virtual Address 152 + * paddr - VM Physical Address 153 + * memslot - Memory region slot for new virtual translation tables 154 + * 155 + * Output Args: None 156 + * 157 + * Return: None 158 + * 159 + * Within @vm, creates a virtual translation for the page starting 160 + * at @vaddr to the page starting at @paddr. 161 + */ 199 162 void virt_pg_map(struct kvm_vm *vm, uint64_t vaddr, uint64_t paddr, 200 - uint32_t pgd_memslot); 163 + uint32_t memslot); 164 + 201 165 vm_paddr_t vm_phy_page_alloc(struct kvm_vm *vm, vm_paddr_t paddr_min, 202 166 uint32_t memslot); 203 167 vm_paddr_t vm_phy_pages_alloc(struct kvm_vm *vm, size_t num, 204 168 vm_paddr_t paddr_min, uint32_t memslot); 205 169 170 + /* 171 + * Create a VM with reasonable defaults 172 + * 173 + * Input Args: 174 + * vcpuid - The id of the single VCPU to add to the VM. 175 + * extra_mem_pages - The size of extra memories to add (this will 176 + * decide how much extra space we will need to 177 + * setup the page tables using memslot 0) 178 + * guest_code - The vCPU's entry point 179 + * 180 + * Output Args: None 181 + * 182 + * Return: 183 + * Pointer to opaque structure that describes the created VM. 184 + */ 206 185 struct kvm_vm *vm_create_default(uint32_t vcpuid, uint64_t extra_mem_size, 207 186 void *guest_code); 187 + 188 + /* 189 + * Adds a vCPU with reasonable defaults (e.g. a stack) 190 + * 191 + * Input Args: 192 + * vm - Virtual Machine 193 + * vcpuid - The id of the VCPU to add to the VM. 194 + * guest_code - The vCPU's entry point 195 + */ 208 196 void vm_vcpu_add_default(struct kvm_vm *vm, uint32_t vcpuid, void *guest_code); 209 197 210 198 bool vm_is_unrestricted_guest(struct kvm_vm *vm);
-17
tools/testing/selftests/kvm/lib/aarch64/processor.c
··· 334 334 aarch64_vcpu_add_default(vm, vcpuid, NULL, guest_code); 335 335 } 336 336 337 - 338 - /* VM VCPU Args Set 339 - * 340 - * Input Args: 341 - * vm - Virtual Machine 342 - * vcpuid - VCPU ID 343 - * num - number of arguments 344 - * ... - arguments, each of type uint64_t 345 - * 346 - * Output Args: None 347 - * 348 - * Return: None 349 - * 350 - * Sets the first num function input arguments to the values 351 - * given as variable args. Each of the variable args is expected to 352 - * be of type uint64_t. The registers set by this function are r0-r7. 353 - */ 354 337 void vcpu_args_set(struct kvm_vm *vm, uint32_t vcpuid, unsigned int num, ...) 355 338 { 356 339 va_list ap;
+48
tools/testing/selftests/kvm/lib/kvm_util_internal.h
··· 53 53 }; 54 54 55 55 struct vcpu *vcpu_find(struct kvm_vm *vm, uint32_t vcpuid); 56 + 57 + /* 58 + * Virtual Translation Tables Dump 59 + * 60 + * Input Args: 61 + * stream - Output FILE stream 62 + * vm - Virtual Machine 63 + * indent - Left margin indent amount 64 + * 65 + * Output Args: None 66 + * 67 + * Return: None 68 + * 69 + * Dumps to the FILE stream given by @stream, the contents of all the 70 + * virtual translation tables for the VM given by @vm. 71 + */ 56 72 void virt_dump(FILE *stream, struct kvm_vm *vm, uint8_t indent); 73 + 74 + /* 75 + * Register Dump 76 + * 77 + * Input Args: 78 + * stream - Output FILE stream 79 + * regs - Registers 80 + * indent - Left margin indent amount 81 + * 82 + * Output Args: None 83 + * 84 + * Return: None 85 + * 86 + * Dumps the state of the registers given by @regs, to the FILE stream 87 + * given by @stream. 88 + */ 57 89 void regs_dump(FILE *stream, struct kvm_regs *regs, uint8_t indent); 90 + 91 + /* 92 + * System Register Dump 93 + * 94 + * Input Args: 95 + * stream - Output FILE stream 96 + * sregs - System registers 97 + * indent - Left margin indent amount 98 + * 99 + * Output Args: None 100 + * 101 + * Return: None 102 + * 103 + * Dumps the state of the system registers given by @sregs, to the FILE stream 104 + * given by @stream. 105 + */ 58 106 void sregs_dump(FILE *stream, struct kvm_sregs *sregs, uint8_t indent); 59 107 60 108 struct userspace_mem_region *
-74
tools/testing/selftests/kvm/lib/s390x/processor.c
··· 51 51 | ((ri < 4 ? (PAGES_PER_REGION - 1) : 0) & REGION_ENTRY_LENGTH); 52 52 } 53 53 54 - /* 55 - * VM Virtual Page Map 56 - * 57 - * Input Args: 58 - * vm - Virtual Machine 59 - * gva - VM Virtual Address 60 - * gpa - VM Physical Address 61 - * memslot - Memory region slot for new virtual translation tables 62 - * 63 - * Output Args: None 64 - * 65 - * Return: None 66 - * 67 - * Within the VM given by vm, creates a virtual translation for the page 68 - * starting at vaddr to the page starting at paddr. 69 - */ 70 54 void virt_pg_map(struct kvm_vm *vm, uint64_t gva, uint64_t gpa, 71 55 uint32_t memslot) 72 56 { ··· 91 107 entry[idx] = gpa; 92 108 } 93 109 94 - /* 95 - * Address Guest Virtual to Guest Physical 96 - * 97 - * Input Args: 98 - * vm - Virtual Machine 99 - * gpa - VM virtual address 100 - * 101 - * Output Args: None 102 - * 103 - * Return: 104 - * Equivalent VM physical address 105 - * 106 - * Translates the VM virtual address given by gva to a VM physical 107 - * address and then locates the memory region containing the VM 108 - * physical address, within the VM given by vm. When found, the host 109 - * virtual address providing the memory to the vm physical address is 110 - * returned. 111 - * A TEST_ASSERT failure occurs if no region containing translated 112 - * VM virtual address exists. 113 - */ 114 110 vm_paddr_t addr_gva2gpa(struct kvm_vm *vm, vm_vaddr_t gva) 115 111 { 116 112 int ri, idx; ··· 160 196 virt_dump_region(stream, vm, indent, vm->pgd); 161 197 } 162 198 163 - /* 164 - * Create a VM with reasonable defaults 165 - * 166 - * Input Args: 167 - * vcpuid - The id of the single VCPU to add to the VM. 168 - * extra_mem_pages - The size of extra memories to add (this will 169 - * decide how much extra space we will need to 170 - * setup the page tables using mem slot 0) 171 - * guest_code - The vCPU's entry point 172 - * 173 - * Output Args: None 174 - * 175 - * Return: 176 - * Pointer to opaque structure that describes the created VM. 177 - */ 178 199 struct kvm_vm *vm_create_default(uint32_t vcpuid, uint64_t extra_mem_pages, 179 200 void *guest_code) 180 201 { ··· 180 231 return vm; 181 232 } 182 233 183 - /* 184 - * Adds a vCPU with reasonable defaults (i.e. a stack and initial PSW) 185 - * 186 - * Input Args: 187 - * vcpuid - The id of the VCPU to add to the VM. 188 - * guest_code - The vCPU's entry point 189 - */ 190 234 void vm_vcpu_add_default(struct kvm_vm *vm, uint32_t vcpuid, void *guest_code) 191 235 { 192 236 size_t stack_size = DEFAULT_STACK_PGS * getpagesize(); ··· 211 269 run->psw_addr = (uintptr_t)guest_code; 212 270 } 213 271 214 - /* VM VCPU Args Set 215 - * 216 - * Input Args: 217 - * vm - Virtual Machine 218 - * vcpuid - VCPU ID 219 - * num - number of arguments 220 - * ... - arguments, each of type uint64_t 221 - * 222 - * Output Args: None 223 - * 224 - * Return: None 225 - * 226 - * Sets the first num function input arguments to the values 227 - * given as variable args. Each of the variable args is expected to 228 - * be of type uint64_t. The registers set by this function are r2-r6. 229 - */ 230 272 void vcpu_args_set(struct kvm_vm *vm, uint32_t vcpuid, unsigned int num, ...) 231 273 { 232 274 va_list ap;
+42 -156
tools/testing/selftests/kvm/lib/x86_64/processor.c
··· 77 77 uint64_t execute_disable:1; 78 78 }; 79 79 80 - /* Register Dump 81 - * 82 - * Input Args: 83 - * indent - Left margin indent amount 84 - * regs - register 85 - * 86 - * Output Args: 87 - * stream - Output FILE stream 88 - * 89 - * Return: None 90 - * 91 - * Dumps the state of the registers given by regs, to the FILE stream 92 - * given by steam. 93 - */ 94 80 void regs_dump(FILE *stream, struct kvm_regs *regs, 95 81 uint8_t indent) 96 82 { ··· 101 115 regs->rip, regs->rflags); 102 116 } 103 117 104 - /* Segment Dump 118 + /* 119 + * Segment Dump 105 120 * 106 121 * Input Args: 107 - * indent - Left margin indent amount 122 + * stream - Output FILE stream 108 123 * segment - KVM segment 124 + * indent - Left margin indent amount 109 125 * 110 - * Output Args: 111 - * stream - Output FILE stream 126 + * Output Args: None 112 127 * 113 128 * Return: None 114 129 * 115 - * Dumps the state of the KVM segment given by segment, to the FILE stream 116 - * given by steam. 130 + * Dumps the state of the KVM segment given by @segment, to the FILE stream 131 + * given by @stream. 117 132 */ 118 133 static void segment_dump(FILE *stream, struct kvm_segment *segment, 119 134 uint8_t indent) ··· 133 146 segment->unusable, segment->padding); 134 147 } 135 148 136 - /* dtable Dump 149 + /* 150 + * dtable Dump 137 151 * 138 152 * Input Args: 139 - * indent - Left margin indent amount 140 - * dtable - KVM dtable 141 - * 142 - * Output Args: 143 153 * stream - Output FILE stream 154 + * dtable - KVM dtable 155 + * indent - Left margin indent amount 156 + * 157 + * Output Args: None 144 158 * 145 159 * Return: None 146 160 * 147 - * Dumps the state of the KVM dtable given by dtable, to the FILE stream 148 - * given by steam. 161 + * Dumps the state of the KVM dtable given by @dtable, to the FILE stream 162 + * given by @stream. 149 163 */ 150 164 static void dtable_dump(FILE *stream, struct kvm_dtable *dtable, 151 165 uint8_t indent) ··· 157 169 dtable->padding[0], dtable->padding[1], dtable->padding[2]); 158 170 } 159 171 160 - /* System Register Dump 161 - * 162 - * Input Args: 163 - * indent - Left margin indent amount 164 - * sregs - System registers 165 - * 166 - * Output Args: 167 - * stream - Output FILE stream 168 - * 169 - * Return: None 170 - * 171 - * Dumps the state of the system registers given by sregs, to the FILE stream 172 - * given by steam. 173 - */ 174 172 void sregs_dump(FILE *stream, struct kvm_sregs *sregs, 175 173 uint8_t indent) 176 174 { ··· 214 240 } 215 241 } 216 242 217 - /* VM Virtual Page Map 218 - * 219 - * Input Args: 220 - * vm - Virtual Machine 221 - * vaddr - VM Virtual Address 222 - * paddr - VM Physical Address 223 - * pgd_memslot - Memory region slot for new virtual translation tables 224 - * 225 - * Output Args: None 226 - * 227 - * Return: None 228 - * 229 - * Within the VM given by vm, creates a virtual translation for the page 230 - * starting at vaddr to the page starting at paddr. 231 - */ 232 243 void virt_pg_map(struct kvm_vm *vm, uint64_t vaddr, uint64_t paddr, 233 244 uint32_t pgd_memslot) 234 245 { ··· 285 326 pte[index[0]].present = 1; 286 327 } 287 328 288 - /* Virtual Translation Tables Dump 289 - * 290 - * Input Args: 291 - * vm - Virtual Machine 292 - * indent - Left margin indent amount 293 - * 294 - * Output Args: 295 - * stream - Output FILE stream 296 - * 297 - * Return: None 298 - * 299 - * Dumps to the FILE stream given by stream, the contents of all the 300 - * virtual translation tables for the VM given by vm. 301 - */ 302 329 void virt_dump(FILE *stream, struct kvm_vm *vm, uint8_t indent) 303 330 { 304 331 struct pageMapL4Entry *pml4e, *pml4e_start; ··· 366 421 } 367 422 } 368 423 369 - /* Set Unusable Segment 424 + /* 425 + * Set Unusable Segment 370 426 * 371 427 * Input Args: None 372 428 * ··· 376 430 * 377 431 * Return: None 378 432 * 379 - * Sets the segment register pointed to by segp to an unusable state. 433 + * Sets the segment register pointed to by @segp to an unusable state. 380 434 */ 381 435 static void kvm_seg_set_unusable(struct kvm_segment *segp) 382 436 { ··· 406 460 } 407 461 408 462 409 - /* Set Long Mode Flat Kernel Code Segment 463 + /* 464 + * Set Long Mode Flat Kernel Code Segment 410 465 * 411 466 * Input Args: 412 467 * vm - VM whose GDT is being filled, or NULL to only write segp ··· 418 471 * 419 472 * Return: None 420 473 * 421 - * Sets up the KVM segment pointed to by segp, to be a code segment 422 - * with the selector value given by selector. 474 + * Sets up the KVM segment pointed to by @segp, to be a code segment 475 + * with the selector value given by @selector. 423 476 */ 424 477 static void kvm_seg_set_kernel_code_64bit(struct kvm_vm *vm, uint16_t selector, 425 478 struct kvm_segment *segp) ··· 438 491 kvm_seg_fill_gdt_64bit(vm, segp); 439 492 } 440 493 441 - /* Set Long Mode Flat Kernel Data Segment 494 + /* 495 + * Set Long Mode Flat Kernel Data Segment 442 496 * 443 497 * Input Args: 444 498 * vm - VM whose GDT is being filled, or NULL to only write segp ··· 450 502 * 451 503 * Return: None 452 504 * 453 - * Sets up the KVM segment pointed to by segp, to be a data segment 454 - * with the selector value given by selector. 505 + * Sets up the KVM segment pointed to by @segp, to be a data segment 506 + * with the selector value given by @selector. 455 507 */ 456 508 static void kvm_seg_set_kernel_data_64bit(struct kvm_vm *vm, uint16_t selector, 457 509 struct kvm_segment *segp) ··· 469 521 kvm_seg_fill_gdt_64bit(vm, segp); 470 522 } 471 523 472 - /* Address Guest Virtual to Guest Physical 473 - * 474 - * Input Args: 475 - * vm - Virtual Machine 476 - * gpa - VM virtual address 477 - * 478 - * Output Args: None 479 - * 480 - * Return: 481 - * Equivalent VM physical address 482 - * 483 - * Translates the VM virtual address given by gva to a VM physical 484 - * address and then locates the memory region containing the VM 485 - * physical address, within the VM given by vm. When found, the host 486 - * virtual address providing the memory to the vm physical address is returned. 487 - * A TEST_ASSERT failure occurs if no region containing translated 488 - * VM virtual address exists. 489 - */ 490 524 vm_paddr_t addr_gva2gpa(struct kvm_vm *vm, vm_vaddr_t gva) 491 525 { 492 526 uint16_t index[4]; ··· 570 640 sregs.cr3 = vm->pgd; 571 641 vcpu_sregs_set(vm, vcpuid, &sregs); 572 642 } 573 - /* Adds a vCPU with reasonable defaults (i.e., a stack) 574 - * 575 - * Input Args: 576 - * vcpuid - The id of the VCPU to add to the VM. 577 - * guest_code - The vCPU's entry point 578 - */ 643 + 579 644 void vm_vcpu_add_default(struct kvm_vm *vm, uint32_t vcpuid, void *guest_code) 580 645 { 581 646 struct kvm_mp_state mp_state; ··· 595 670 vcpu_set_mp_state(vm, vcpuid, &mp_state); 596 671 } 597 672 598 - /* Allocate an instance of struct kvm_cpuid2 673 + /* 674 + * Allocate an instance of struct kvm_cpuid2 599 675 * 600 676 * Input Args: None 601 677 * ··· 629 703 return cpuid; 630 704 } 631 705 632 - /* KVM Supported CPUID Get 706 + /* 707 + * KVM Supported CPUID Get 633 708 * 634 709 * Input Args: None 635 710 * ··· 662 735 return cpuid; 663 736 } 664 737 665 - /* Locate a cpuid entry. 738 + /* 739 + * Locate a cpuid entry. 666 740 * 667 741 * Input Args: 668 - * cpuid: The cpuid. 669 742 * function: The function of the cpuid entry to find. 743 + * index: The index of the cpuid entry. 670 744 * 671 745 * Output Args: None 672 746 * ··· 694 766 return entry; 695 767 } 696 768 697 - /* VM VCPU CPUID Set 769 + /* 770 + * VM VCPU CPUID Set 698 771 * 699 772 * Input Args: 700 773 * vm - Virtual Machine ··· 722 793 723 794 } 724 795 725 - /* Create a VM with reasonable defaults 726 - * 727 - * Input Args: 728 - * vcpuid - The id of the single VCPU to add to the VM. 729 - * extra_mem_pages - The size of extra memories to add (this will 730 - * decide how much extra space we will need to 731 - * setup the page tables using mem slot 0) 732 - * guest_code - The vCPU's entry point 733 - * 734 - * Output Args: None 735 - * 736 - * Return: 737 - * Pointer to opaque structure that describes the created VM. 738 - */ 739 796 struct kvm_vm *vm_create_default(uint32_t vcpuid, uint64_t extra_mem_pages, 740 797 void *guest_code) 741 798 { ··· 752 837 return vm; 753 838 } 754 839 755 - /* VCPU Get MSR 840 + /* 841 + * VCPU Get MSR 756 842 * 757 843 * Input Args: 758 844 * vm - Virtual Machine ··· 785 869 return buffer.entry.data; 786 870 } 787 871 788 - /* _VCPU Set MSR 872 + /* 873 + * _VCPU Set MSR 789 874 * 790 875 * Input Args: 791 876 * vm - Virtual Machine ··· 819 902 return r; 820 903 } 821 904 822 - /* VCPU Set MSR 905 + /* 906 + * VCPU Set MSR 823 907 * 824 908 * Input Args: 825 909 * vm - Virtual Machine ··· 844 926 " rc: %i errno: %i", r, errno); 845 927 } 846 928 847 - /* VM VCPU Args Set 848 - * 849 - * Input Args: 850 - * vm - Virtual Machine 851 - * vcpuid - VCPU ID 852 - * num - number of arguments 853 - * ... - arguments, each of type uint64_t 854 - * 855 - * Output Args: None 856 - * 857 - * Return: None 858 - * 859 - * Sets the first num function input arguments to the values 860 - * given as variable args. Each of the variable args is expected to 861 - * be of type uint64_t. 862 - */ 863 929 void vcpu_args_set(struct kvm_vm *vm, uint32_t vcpuid, unsigned int num, ...) 864 930 { 865 931 va_list ap; ··· 878 976 va_end(ap); 879 977 } 880 978 881 - /* 882 - * VM VCPU Dump 883 - * 884 - * Input Args: 885 - * vm - Virtual Machine 886 - * vcpuid - VCPU ID 887 - * indent - Left margin indent amount 888 - * 889 - * Output Args: 890 - * stream - Output FILE stream 891 - * 892 - * Return: None 893 - * 894 - * Dumps the current state of the VCPU specified by vcpuid, within the VM 895 - * given by vm, to the FILE stream given by stream. 896 - */ 897 979 void vcpu_dump(FILE *stream, struct kvm_vm *vm, uint32_t vcpuid, uint8_t indent) 898 980 { 899 981 struct kvm_regs regs;