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

Merge tag 'kvm-x86-selftests-6.17' of https://github.com/kvm-x86/linux into HEAD

KVM selftests changes for 6.17

- Fix a comment typo.

- Verify KVM is loaded when getting any KVM module param so that attempting to
run a selftest without kvm.ko loaded results in a SKIP message about KVM not
being loaded/enabled, versus some random parameter not existing.

- SKIP tests that hit EACCES when attempting to access a file, with a "Root
required?" help message. In most cases, the test just needs to be run with
elevated permissions.

+30 -23
+2 -5
tools/testing/selftests/kvm/access_tracking_perf_test.c
··· 596 596 if (ret) 597 597 return ret; 598 598 } else { 599 - page_idle_fd = open("/sys/kernel/mm/page_idle/bitmap", O_RDWR); 600 - __TEST_REQUIRE(page_idle_fd >= 0, 601 - "Couldn't open /sys/kernel/mm/page_idle/bitmap. " 602 - "Is CONFIG_IDLE_PAGE_TRACKING enabled?"); 603 - 599 + page_idle_fd = __open_path_or_exit("/sys/kernel/mm/page_idle/bitmap", O_RDWR, 600 + "Is CONFIG_IDLE_PAGE_TRACKING enabled?"); 604 601 close(page_idle_fd); 605 602 606 603 puts("Using page_idle for aging");
+1
tools/testing/selftests/kvm/include/kvm_util.h
··· 256 256 }; 257 257 extern const struct vm_guest_mode_params vm_guest_mode_params[]; 258 258 259 + int __open_path_or_exit(const char *path, int flags, const char *enoent_help); 259 260 int open_path_or_exit(const char *path, int flags); 260 261 int open_kvm_dev_path_or_exit(void); 261 262
+5 -1
tools/testing/selftests/kvm/include/x86/processor.h
··· 1150 1150 1151 1151 void kvm_get_cpu_address_width(unsigned int *pa_bits, unsigned int *va_bits); 1152 1152 void kvm_init_vm_address_properties(struct kvm_vm *vm); 1153 - bool vm_is_unrestricted_guest(struct kvm_vm *vm); 1154 1153 1155 1154 struct ex_regs { 1156 1155 uint64_t rax, rcx, rdx, rbx; ··· 1322 1323 static inline bool kvm_is_forced_emulation_enabled(void) 1323 1324 { 1324 1325 return !!get_kvm_param_integer("force_emulation_prefix"); 1326 + } 1327 + 1328 + static inline bool kvm_is_unrestricted_guest_enabled(void) 1329 + { 1330 + return get_kvm_intel_param_bool("unrestricted_guest"); 1325 1331 } 1326 1332 1327 1333 uint64_t *__vm_get_page_table_entry(struct kvm_vm *vm, uint64_t vaddr,
+19 -4
tools/testing/selftests/kvm/lib/kvm_util.c
··· 26 26 27 27 static int vcpu_mmap_sz(void); 28 28 29 - int open_path_or_exit(const char *path, int flags) 29 + int __open_path_or_exit(const char *path, int flags, const char *enoent_help) 30 30 { 31 31 int fd; 32 32 33 33 fd = open(path, flags); 34 - __TEST_REQUIRE(fd >= 0 || errno != ENOENT, "Cannot open %s: %s", path, strerror(errno)); 35 - TEST_ASSERT(fd >= 0, "Failed to open '%s'", path); 34 + if (fd < 0) 35 + goto error; 36 36 37 37 return fd; 38 + 39 + error: 40 + if (errno == EACCES || errno == ENOENT) 41 + ksft_exit_skip("- Cannot open '%s': %s. %s\n", 42 + path, strerror(errno), 43 + errno == EACCES ? "Root required?" : enoent_help); 44 + TEST_FAIL("Failed to open '%s'", path); 45 + } 46 + 47 + int open_path_or_exit(const char *path, int flags) 48 + { 49 + return __open_path_or_exit(path, flags, ""); 38 50 } 39 51 40 52 /* ··· 60 48 */ 61 49 static int _open_kvm_dev_path_or_exit(int flags) 62 50 { 63 - return open_path_or_exit(KVM_DEV_PATH, flags); 51 + return __open_path_or_exit(KVM_DEV_PATH, flags, "Is KVM loaded and enabled?"); 64 52 } 65 53 66 54 int open_kvm_dev_path_or_exit(void) ··· 75 63 char path[path_size]; 76 64 ssize_t bytes_read; 77 65 int fd, r; 66 + 67 + /* Verify KVM is loaded, to provide a more helpful SKIP message. */ 68 + close(open_kvm_dev_path_or_exit()); 78 69 79 70 r = snprintf(path, path_size, "/sys/module/%s/parameters/%s", 80 71 module_name, param);
+2 -2
tools/testing/selftests/kvm/lib/sparsebit.c
··· 116 116 * 117 117 * + A node with all mask bits set only occurs when the last bit 118 118 * described by the previous node is not equal to this nodes 119 - * starting index - 1. All such occurences of this condition are 119 + * starting index - 1. All such occurrences of this condition are 120 120 * avoided by moving the setting of the nodes mask bits into 121 121 * the previous nodes num_after setting. 122 122 * ··· 592 592 * 593 593 * + A node with all mask bits set only occurs when the last bit 594 594 * described by the previous node is not equal to this nodes 595 - * starting index - 1. All such occurences of this condition are 595 + * starting index - 1. All such occurrences of this condition are 596 596 * avoided by moving the setting of the nodes mask bits into 597 597 * the previous nodes num_after setting. 598 598 */
-10
tools/testing/selftests/kvm/lib/x86/processor.c
··· 1264 1264 return min(max_gfn, ht_gfn - 1); 1265 1265 } 1266 1266 1267 - /* Returns true if kvm_intel was loaded with unrestricted_guest=1. */ 1268 - bool vm_is_unrestricted_guest(struct kvm_vm *vm) 1269 - { 1270 - /* Ensure that a KVM vendor-specific module is loaded. */ 1271 - if (vm == NULL) 1272 - close(open_kvm_dev_path_or_exit()); 1273 - 1274 - return get_kvm_intel_param_bool("unrestricted_guest"); 1275 - } 1276 - 1277 1267 void kvm_selftest_arch_init(void) 1278 1268 { 1279 1269 host_cpu_is_intel = this_cpu_is_intel();
+1 -1
tools/testing/selftests/kvm/x86/vmx_exception_with_invalid_guest_state.c
··· 110 110 struct kvm_vm *vm; 111 111 112 112 TEST_REQUIRE(host_cpu_is_intel); 113 - TEST_REQUIRE(!vm_is_unrestricted_guest(NULL)); 113 + TEST_REQUIRE(!kvm_is_unrestricted_guest_enabled()); 114 114 115 115 vm = vm_create_with_one_vcpu(&vcpu, guest_code); 116 116 get_set_sigalrm_vcpu(vcpu);