mirror of
https://github.com/torvalds/linux.git
synced 2026-06-03 20:14:06 +02:00
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.
This commit is contained in:
commit
b4733cd5be
|
|
@ -596,11 +596,8 @@ int main(int argc, char *argv[])
|
|||
if (ret)
|
||||
return ret;
|
||||
} else {
|
||||
page_idle_fd = open("/sys/kernel/mm/page_idle/bitmap", O_RDWR);
|
||||
__TEST_REQUIRE(page_idle_fd >= 0,
|
||||
"Couldn't open /sys/kernel/mm/page_idle/bitmap. "
|
||||
"Is CONFIG_IDLE_PAGE_TRACKING enabled?");
|
||||
|
||||
page_idle_fd = __open_path_or_exit("/sys/kernel/mm/page_idle/bitmap", O_RDWR,
|
||||
"Is CONFIG_IDLE_PAGE_TRACKING enabled?");
|
||||
close(page_idle_fd);
|
||||
|
||||
puts("Using page_idle for aging");
|
||||
|
|
|
|||
|
|
@ -256,6 +256,7 @@ struct vm_guest_mode_params {
|
|||
};
|
||||
extern const struct vm_guest_mode_params vm_guest_mode_params[];
|
||||
|
||||
int __open_path_or_exit(const char *path, int flags, const char *enoent_help);
|
||||
int open_path_or_exit(const char *path, int flags);
|
||||
int open_kvm_dev_path_or_exit(void);
|
||||
|
||||
|
|
|
|||
|
|
@ -1150,7 +1150,6 @@ do { \
|
|||
|
||||
void kvm_get_cpu_address_width(unsigned int *pa_bits, unsigned int *va_bits);
|
||||
void kvm_init_vm_address_properties(struct kvm_vm *vm);
|
||||
bool vm_is_unrestricted_guest(struct kvm_vm *vm);
|
||||
|
||||
struct ex_regs {
|
||||
uint64_t rax, rcx, rdx, rbx;
|
||||
|
|
@ -1325,6 +1324,11 @@ static inline bool kvm_is_forced_emulation_enabled(void)
|
|||
return !!get_kvm_param_integer("force_emulation_prefix");
|
||||
}
|
||||
|
||||
static inline bool kvm_is_unrestricted_guest_enabled(void)
|
||||
{
|
||||
return get_kvm_intel_param_bool("unrestricted_guest");
|
||||
}
|
||||
|
||||
uint64_t *__vm_get_page_table_entry(struct kvm_vm *vm, uint64_t vaddr,
|
||||
int *level);
|
||||
uint64_t *vm_get_page_table_entry(struct kvm_vm *vm, uint64_t vaddr);
|
||||
|
|
|
|||
|
|
@ -26,15 +26,27 @@ static uint32_t last_guest_seed;
|
|||
|
||||
static int vcpu_mmap_sz(void);
|
||||
|
||||
int open_path_or_exit(const char *path, int flags)
|
||||
int __open_path_or_exit(const char *path, int flags, const char *enoent_help)
|
||||
{
|
||||
int fd;
|
||||
|
||||
fd = open(path, flags);
|
||||
__TEST_REQUIRE(fd >= 0 || errno != ENOENT, "Cannot open %s: %s", path, strerror(errno));
|
||||
TEST_ASSERT(fd >= 0, "Failed to open '%s'", path);
|
||||
if (fd < 0)
|
||||
goto error;
|
||||
|
||||
return fd;
|
||||
|
||||
error:
|
||||
if (errno == EACCES || errno == ENOENT)
|
||||
ksft_exit_skip("- Cannot open '%s': %s. %s\n",
|
||||
path, strerror(errno),
|
||||
errno == EACCES ? "Root required?" : enoent_help);
|
||||
TEST_FAIL("Failed to open '%s'", path);
|
||||
}
|
||||
|
||||
int open_path_or_exit(const char *path, int flags)
|
||||
{
|
||||
return __open_path_or_exit(path, flags, "");
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -48,7 +60,7 @@ int open_path_or_exit(const char *path, int flags)
|
|||
*/
|
||||
static int _open_kvm_dev_path_or_exit(int flags)
|
||||
{
|
||||
return open_path_or_exit(KVM_DEV_PATH, flags);
|
||||
return __open_path_or_exit(KVM_DEV_PATH, flags, "Is KVM loaded and enabled?");
|
||||
}
|
||||
|
||||
int open_kvm_dev_path_or_exit(void)
|
||||
|
|
@ -64,6 +76,9 @@ static ssize_t get_module_param(const char *module_name, const char *param,
|
|||
ssize_t bytes_read;
|
||||
int fd, r;
|
||||
|
||||
/* Verify KVM is loaded, to provide a more helpful SKIP message. */
|
||||
close(open_kvm_dev_path_or_exit());
|
||||
|
||||
r = snprintf(path, path_size, "/sys/module/%s/parameters/%s",
|
||||
module_name, param);
|
||||
TEST_ASSERT(r < path_size,
|
||||
|
|
|
|||
|
|
@ -116,7 +116,7 @@
|
|||
*
|
||||
* + A node with all mask bits set only occurs when the last bit
|
||||
* described by the previous node is not equal to this nodes
|
||||
* starting index - 1. All such occurences of this condition are
|
||||
* starting index - 1. All such occurrences of this condition are
|
||||
* avoided by moving the setting of the nodes mask bits into
|
||||
* the previous nodes num_after setting.
|
||||
*
|
||||
|
|
@ -592,7 +592,7 @@ static struct node *node_split(struct sparsebit *s, sparsebit_idx_t idx)
|
|||
*
|
||||
* + A node with all mask bits set only occurs when the last bit
|
||||
* described by the previous node is not equal to this nodes
|
||||
* starting index - 1. All such occurences of this condition are
|
||||
* starting index - 1. All such occurrences of this condition are
|
||||
* avoided by moving the setting of the nodes mask bits into
|
||||
* the previous nodes num_after setting.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1264,16 +1264,6 @@ unsigned long vm_compute_max_gfn(struct kvm_vm *vm)
|
|||
return min(max_gfn, ht_gfn - 1);
|
||||
}
|
||||
|
||||
/* Returns true if kvm_intel was loaded with unrestricted_guest=1. */
|
||||
bool vm_is_unrestricted_guest(struct kvm_vm *vm)
|
||||
{
|
||||
/* Ensure that a KVM vendor-specific module is loaded. */
|
||||
if (vm == NULL)
|
||||
close(open_kvm_dev_path_or_exit());
|
||||
|
||||
return get_kvm_intel_param_bool("unrestricted_guest");
|
||||
}
|
||||
|
||||
void kvm_selftest_arch_init(void)
|
||||
{
|
||||
host_cpu_is_intel = this_cpu_is_intel();
|
||||
|
|
|
|||
|
|
@ -110,7 +110,7 @@ int main(int argc, char *argv[])
|
|||
struct kvm_vm *vm;
|
||||
|
||||
TEST_REQUIRE(host_cpu_is_intel);
|
||||
TEST_REQUIRE(!vm_is_unrestricted_guest(NULL));
|
||||
TEST_REQUIRE(!kvm_is_unrestricted_guest_enabled());
|
||||
|
||||
vm = vm_create_with_one_vcpu(&vcpu, guest_code);
|
||||
get_set_sigalrm_vcpu(vcpu);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user