Commit dee7ea42 authored by Paolo Bonzini's avatar Paolo Bonzini

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

KVM selftests treewide updates for 6.10:

 - Define _GNU_SOURCE for all selftests to fix a warning that was introduced by
   a change to kselftest_harness.h late in the 6.9 cycle, and because forcing
   every test to #define _GNU_SOURCE is painful.

 - Provide a global psuedo-RNG instance for all tests, so that library code can
   generate random, but determinstic numbers.

 - Use the global pRNG to randomly force emulation of select writes from guest
   code on x86, e.g. to help validate KVM's emulation of locked accesses.

 - Rename kvm_util_base.h back to kvm_util.h, as the weird layer of indirection
   was added purely to avoid manually #including ucall_common.h in a handful of
   locations.

 - Allocate and initialize x86's GDT, IDT, TSS, segments, and default exception
   handlers at VM creation, instead of forcing tests to manually trigger the
   related setup.
parents 31a6cd7f b093f87f
...@@ -230,8 +230,8 @@ LINUX_TOOL_ARCH_INCLUDE = $(top_srcdir)/tools/arch/$(ARCH)/include ...@@ -230,8 +230,8 @@ LINUX_TOOL_ARCH_INCLUDE = $(top_srcdir)/tools/arch/$(ARCH)/include
endif endif
CFLAGS += -Wall -Wstrict-prototypes -Wuninitialized -O2 -g -std=gnu99 \ CFLAGS += -Wall -Wstrict-prototypes -Wuninitialized -O2 -g -std=gnu99 \
-Wno-gnu-variable-sized-type-not-at-end -MD -MP -DCONFIG_64BIT \ -Wno-gnu-variable-sized-type-not-at-end -MD -MP -DCONFIG_64BIT \
-fno-builtin-memcmp -fno-builtin-memcpy -fno-builtin-memset \ -D_GNU_SOURCE -fno-builtin-memcmp -fno-builtin-memcpy \
-fno-builtin-strnlen \ -fno-builtin-memset -fno-builtin-strnlen \
-fno-stack-protector -fno-PIE -I$(LINUX_TOOL_INCLUDE) \ -fno-stack-protector -fno-PIE -I$(LINUX_TOOL_INCLUDE) \
-I$(LINUX_TOOL_ARCH_INCLUDE) -I$(LINUX_HDR_PATH) -Iinclude \ -I$(LINUX_TOOL_ARCH_INCLUDE) -I$(LINUX_HDR_PATH) -Iinclude \
-I$(<D) -Iinclude/$(ARCH_DIR) -I ../rseq -I.. $(EXTRA_CFLAGS) \ -I$(<D) -Iinclude/$(ARCH_DIR) -I ../rseq -I.. $(EXTRA_CFLAGS) \
......
...@@ -5,13 +5,12 @@ ...@@ -5,13 +5,12 @@
* *
* Copyright (c) 2021, Google LLC. * Copyright (c) 2021, Google LLC.
*/ */
#define _GNU_SOURCE
#include "arch_timer.h" #include "arch_timer.h"
#include "delay.h" #include "delay.h"
#include "gic.h" #include "gic.h"
#include "processor.h" #include "processor.h"
#include "timer_test.h" #include "timer_test.h"
#include "ucall_common.h"
#include "vgic.h" #include "vgic.h"
enum guest_stage { enum guest_stage {
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
* hugetlbfs with a hole). It checks that the expected handling method is * hugetlbfs with a hole). It checks that the expected handling method is
* called (e.g., uffd faults with the right address and write/read flag). * called (e.g., uffd faults with the right address and write/read flag).
*/ */
#define _GNU_SOURCE
#include <linux/bitmap.h> #include <linux/bitmap.h>
#include <fcntl.h> #include <fcntl.h>
#include <test_util.h> #include <test_util.h>
......
...@@ -11,8 +11,6 @@ ...@@ -11,8 +11,6 @@
* KVM_SYSTEM_EVENT_SUSPEND UAPI. * KVM_SYSTEM_EVENT_SUSPEND UAPI.
*/ */
#define _GNU_SOURCE
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/psci.h> #include <linux/psci.h>
#include <asm/cputype.h> #include <asm/cputype.h>
......
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
* *
* Copyright (C) 2020, Red Hat, Inc. * Copyright (C) 2020, Red Hat, Inc.
*/ */
#define _GNU_SOURCE
#include <linux/kernel.h> #include <linux/kernel.h>
#include <sys/syscall.h> #include <sys/syscall.h>
#include <asm/kvm.h> #include <asm/kvm.h>
......
...@@ -19,9 +19,6 @@ ...@@ -19,9 +19,6 @@
* *
* Copyright (c) 2021, Google LLC. * Copyright (c) 2021, Google LLC.
*/ */
#define _GNU_SOURCE
#include <stdlib.h> #include <stdlib.h>
#include <pthread.h> #include <pthread.h>
#include <linux/sizes.h> #include <linux/sizes.h>
...@@ -29,6 +26,7 @@ ...@@ -29,6 +26,7 @@
#include <sys/sysinfo.h> #include <sys/sysinfo.h>
#include "timer_test.h" #include "timer_test.h"
#include "ucall_common.h"
struct test_args test_args = { struct test_args test_args = {
.nr_vcpus = NR_VCPUS_DEF, .nr_vcpus = NR_VCPUS_DEF,
......
...@@ -6,9 +6,6 @@ ...@@ -6,9 +6,6 @@
* Copyright (C) 2018, Red Hat, Inc. * Copyright (C) 2018, Red Hat, Inc.
* Copyright (C) 2019, Google, Inc. * Copyright (C) 2019, Google, Inc.
*/ */
#define _GNU_SOURCE /* for pipe2 */
#include <inttypes.h> #include <inttypes.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
...@@ -21,6 +18,7 @@ ...@@ -21,6 +18,7 @@
#include "test_util.h" #include "test_util.h"
#include "memstress.h" #include "memstress.h"
#include "guest_modes.h" #include "guest_modes.h"
#include "ucall_common.h"
#include "userfaultfd_util.h" #include "userfaultfd_util.h"
#ifdef __NR_userfaultfd #ifdef __NR_userfaultfd
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "test_util.h" #include "test_util.h"
#include "memstress.h" #include "memstress.h"
#include "guest_modes.h" #include "guest_modes.h"
#include "ucall_common.h"
#ifdef __aarch64__ #ifdef __aarch64__
#include "aarch64/vgic.h" #include "aarch64/vgic.h"
...@@ -129,7 +130,6 @@ struct test_params { ...@@ -129,7 +130,6 @@ struct test_params {
enum vm_mem_backing_src_type backing_src; enum vm_mem_backing_src_type backing_src;
int slots; int slots;
uint32_t write_percent; uint32_t write_percent;
uint32_t random_seed;
bool random_access; bool random_access;
}; };
...@@ -153,8 +153,6 @@ static void run_test(enum vm_guest_mode mode, void *arg) ...@@ -153,8 +153,6 @@ static void run_test(enum vm_guest_mode mode, void *arg)
p->slots, p->backing_src, p->slots, p->backing_src,
p->partition_vcpu_memory_access); p->partition_vcpu_memory_access);
pr_info("Random seed: %u\n", p->random_seed);
memstress_set_random_seed(vm, p->random_seed);
memstress_set_write_percent(vm, p->write_percent); memstress_set_write_percent(vm, p->write_percent);
guest_num_pages = (nr_vcpus * guest_percpu_mem_size) >> vm->page_shift; guest_num_pages = (nr_vcpus * guest_percpu_mem_size) >> vm->page_shift;
...@@ -343,11 +341,13 @@ int main(int argc, char *argv[]) ...@@ -343,11 +341,13 @@ int main(int argc, char *argv[])
.partition_vcpu_memory_access = true, .partition_vcpu_memory_access = true,
.backing_src = DEFAULT_VM_MEM_SRC, .backing_src = DEFAULT_VM_MEM_SRC,
.slots = 1, .slots = 1,
.random_seed = 1,
.write_percent = 100, .write_percent = 100,
}; };
int opt; int opt;
/* Override the seed to be deterministic by default. */
guest_random_seed = 1;
dirty_log_manual_caps = dirty_log_manual_caps =
kvm_check_cap(KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2); kvm_check_cap(KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2);
dirty_log_manual_caps &= (KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE | dirty_log_manual_caps &= (KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE |
...@@ -392,7 +392,7 @@ int main(int argc, char *argv[]) ...@@ -392,7 +392,7 @@ int main(int argc, char *argv[])
p.phys_offset = strtoull(optarg, NULL, 0); p.phys_offset = strtoull(optarg, NULL, 0);
break; break;
case 'r': case 'r':
p.random_seed = atoi_positive("Random seed", optarg); guest_random_seed = atoi_positive("Random seed", optarg);
break; break;
case 's': case 's':
p.backing_src = parse_backing_src_type(optarg); p.backing_src = parse_backing_src_type(optarg);
......
...@@ -4,9 +4,6 @@ ...@@ -4,9 +4,6 @@
* *
* Copyright (C) 2018, Red Hat, Inc. * Copyright (C) 2018, Red Hat, Inc.
*/ */
#define _GNU_SOURCE /* for program_invocation_name */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <pthread.h> #include <pthread.h>
...@@ -23,6 +20,7 @@ ...@@ -23,6 +20,7 @@
#include "test_util.h" #include "test_util.h"
#include "guest_modes.h" #include "guest_modes.h"
#include "processor.h" #include "processor.h"
#include "ucall_common.h"
#define DIRTY_MEM_BITS 30 /* 1G */ #define DIRTY_MEM_BITS 30 /* 1G */
#define PAGE_SHIFT_4K 12 #define PAGE_SHIFT_4K 12
...@@ -76,7 +74,6 @@ ...@@ -76,7 +74,6 @@
static uint64_t host_page_size; static uint64_t host_page_size;
static uint64_t guest_page_size; static uint64_t guest_page_size;
static uint64_t guest_num_pages; static uint64_t guest_num_pages;
static uint64_t random_array[TEST_PAGES_PER_LOOP];
static uint64_t iteration; static uint64_t iteration;
/* /*
...@@ -109,19 +106,19 @@ static void guest_code(void) ...@@ -109,19 +106,19 @@ static void guest_code(void)
*/ */
for (i = 0; i < guest_num_pages; i++) { for (i = 0; i < guest_num_pages; i++) {
addr = guest_test_virt_mem + i * guest_page_size; addr = guest_test_virt_mem + i * guest_page_size;
*(uint64_t *)addr = READ_ONCE(iteration); vcpu_arch_put_guest(*(uint64_t *)addr, READ_ONCE(iteration));
} }
while (true) { while (true) {
for (i = 0; i < TEST_PAGES_PER_LOOP; i++) { for (i = 0; i < TEST_PAGES_PER_LOOP; i++) {
addr = guest_test_virt_mem; addr = guest_test_virt_mem;
addr += (READ_ONCE(random_array[i]) % guest_num_pages) addr += (guest_random_u64(&guest_rng) % guest_num_pages)
* guest_page_size; * guest_page_size;
addr = align_down(addr, host_page_size); addr = align_down(addr, host_page_size);
*(uint64_t *)addr = READ_ONCE(iteration);
vcpu_arch_put_guest(*(uint64_t *)addr, READ_ONCE(iteration));
} }
/* Tell the host that we need more random numbers */
GUEST_SYNC(1); GUEST_SYNC(1);
} }
} }
...@@ -508,20 +505,10 @@ static void log_mode_after_vcpu_run(struct kvm_vcpu *vcpu, int ret, int err) ...@@ -508,20 +505,10 @@ static void log_mode_after_vcpu_run(struct kvm_vcpu *vcpu, int ret, int err)
mode->after_vcpu_run(vcpu, ret, err); mode->after_vcpu_run(vcpu, ret, err);
} }
static void generate_random_array(uint64_t *guest_array, uint64_t size)
{
uint64_t i;
for (i = 0; i < size; i++)
guest_array[i] = random();
}
static void *vcpu_worker(void *data) static void *vcpu_worker(void *data)
{ {
int ret; int ret;
struct kvm_vcpu *vcpu = data; struct kvm_vcpu *vcpu = data;
struct kvm_vm *vm = vcpu->vm;
uint64_t *guest_array;
uint64_t pages_count = 0; uint64_t pages_count = 0;
struct kvm_signal_mask *sigmask = alloca(offsetof(struct kvm_signal_mask, sigset) struct kvm_signal_mask *sigmask = alloca(offsetof(struct kvm_signal_mask, sigset)
+ sizeof(sigset_t)); + sizeof(sigset_t));
...@@ -540,11 +527,8 @@ static void *vcpu_worker(void *data) ...@@ -540,11 +527,8 @@ static void *vcpu_worker(void *data)
sigemptyset(sigset); sigemptyset(sigset);
sigaddset(sigset, SIG_IPI); sigaddset(sigset, SIG_IPI);
guest_array = addr_gva2hva(vm, (vm_vaddr_t)random_array);
while (!READ_ONCE(host_quit)) { while (!READ_ONCE(host_quit)) {
/* Clear any existing kick signals */ /* Clear any existing kick signals */
generate_random_array(guest_array, TEST_PAGES_PER_LOOP);
pages_count += TEST_PAGES_PER_LOOP; pages_count += TEST_PAGES_PER_LOOP;
/* Let the guest dirty the random pages */ /* Let the guest dirty the random pages */
ret = __vcpu_run(vcpu); ret = __vcpu_run(vcpu);
......
...@@ -4,8 +4,6 @@ ...@@ -4,8 +4,6 @@
* *
* Author: Chao Peng <chao.p.peng@linux.intel.com> * Author: Chao Peng <chao.p.peng@linux.intel.com>
*/ */
#define _GNU_SOURCE
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
...@@ -19,8 +17,8 @@ ...@@ -19,8 +17,8 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include "kvm_util.h"
#include "test_util.h" #include "test_util.h"
#include "kvm_util_base.h"
static void test_file_read_write(int fd) static void test_file_read_write(int fd)
{ {
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "test_util.h" #include "test_util.h"
#include "kvm_util.h" #include "kvm_util.h"
#include "processor.h" #include "processor.h"
#include "ucall_common.h"
struct guest_vals { struct guest_vals {
uint64_t a; uint64_t a;
......
...@@ -4,9 +4,6 @@ ...@@ -4,9 +4,6 @@
* kvm_arch_hardware_disable is called and it attempts to unregister the user * kvm_arch_hardware_disable is called and it attempts to unregister the user
* return notifiers. * return notifiers.
*/ */
#define _GNU_SOURCE
#include <fcntl.h> #include <fcntl.h>
#include <pthread.h> #include <pthread.h>
#include <semaphore.h> #include <semaphore.h>
......
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
#define SELFTEST_KVM_PROCESSOR_H #define SELFTEST_KVM_PROCESSOR_H
#include "kvm_util.h" #include "kvm_util.h"
#include "ucall_common.h"
#include <linux/stringify.h> #include <linux/stringify.h>
#include <linux/types.h> #include <linux/types.h>
#include <asm/sysreg.h> #include <asm/sysreg.h>
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#ifndef SELFTEST_KVM_UCALL_H #ifndef SELFTEST_KVM_UCALL_H
#define SELFTEST_KVM_UCALL_H #define SELFTEST_KVM_UCALL_H
#include "kvm_util_base.h" #include "kvm_util.h"
#define UCALL_EXIT_REASON KVM_EXIT_MMIO #define UCALL_EXIT_REASON KVM_EXIT_MMIO
......
...@@ -27,12 +27,12 @@ ...@@ -27,12 +27,12 @@
/* /*
* Provide a version of static_assert() that is guaranteed to have an optional * Provide a version of static_assert() that is guaranteed to have an optional
* message param. If _ISOC11_SOURCE is defined, glibc (/usr/include/assert.h) * message param. _GNU_SOURCE is defined for all KVM selftests, _GNU_SOURCE
* #undefs and #defines static_assert() as a direct alias to _Static_assert(), * implies _ISOC11_SOURCE, and if _ISOC11_SOURCE is defined, glibc #undefs and
* i.e. effectively makes the message mandatory. Many KVM selftests #define * #defines static_assert() as a direct alias to _Static_assert() (see
* _GNU_SOURCE for various reasons, and _GNU_SOURCE implies _ISOC11_SOURCE. As * usr/include/assert.h). Define a custom macro instead of redefining
* a result, static_assert() behavior is non-deterministic and may or may not * static_assert() to avoid creating non-deterministic behavior that is
* require a message depending on #include order. * dependent on include order.
*/ */
#define __kvm_static_assert(expr, msg, ...) _Static_assert(expr, msg) #define __kvm_static_assert(expr, msg, ...) _Static_assert(expr, msg)
#define kvm_static_assert(expr, ...) __kvm_static_assert(expr, ##__VA_ARGS__, #expr) #define kvm_static_assert(expr, ...) __kvm_static_assert(expr, ##__VA_ARGS__, #expr)
...@@ -609,6 +609,9 @@ void *addr_gva2hva(struct kvm_vm *vm, vm_vaddr_t gva); ...@@ -609,6 +609,9 @@ void *addr_gva2hva(struct kvm_vm *vm, vm_vaddr_t gva);
vm_paddr_t addr_hva2gpa(struct kvm_vm *vm, void *hva); vm_paddr_t addr_hva2gpa(struct kvm_vm *vm, void *hva);
void *addr_gpa2alias(struct kvm_vm *vm, vm_paddr_t gpa); void *addr_gpa2alias(struct kvm_vm *vm, vm_paddr_t gpa);
#ifndef vcpu_arch_put_guest
#define vcpu_arch_put_guest(mem, val) do { (mem) = (val); } while (0)
#endif
static inline vm_paddr_t vm_untag_gpa(struct kvm_vm *vm, vm_paddr_t gpa) static inline vm_paddr_t vm_untag_gpa(struct kvm_vm *vm, vm_paddr_t gpa)
{ {
......
/* SPDX-License-Identifier: GPL-2.0-only */
#ifndef SELFTEST_KVM_UTIL_TYPES_H
#define SELFTEST_KVM_UTIL_TYPES_H
/*
* Provide a version of static_assert() that is guaranteed to have an optional
* message param. _GNU_SOURCE is defined for all KVM selftests, _GNU_SOURCE
* implies _ISOC11_SOURCE, and if _ISOC11_SOURCE is defined, glibc #undefs and
* #defines static_assert() as a direct alias to _Static_assert() (see
* usr/include/assert.h). Define a custom macro instead of redefining
* static_assert() to avoid creating non-deterministic behavior that is
* dependent on include order.
*/
#define __kvm_static_assert(expr, msg, ...) _Static_assert(expr, msg)
#define kvm_static_assert(expr, ...) __kvm_static_assert(expr, ##__VA_ARGS__, #expr)
typedef uint64_t vm_paddr_t; /* Virtual Machine (Guest) physical address */
typedef uint64_t vm_vaddr_t; /* Virtual Machine (Guest) virtual address */
#endif /* SELFTEST_KVM_UTIL_TYPES_H */
...@@ -62,7 +62,6 @@ struct kvm_vm *memstress_create_vm(enum vm_guest_mode mode, int nr_vcpus, ...@@ -62,7 +62,6 @@ struct kvm_vm *memstress_create_vm(enum vm_guest_mode mode, int nr_vcpus,
void memstress_destroy_vm(struct kvm_vm *vm); void memstress_destroy_vm(struct kvm_vm *vm);
void memstress_set_write_percent(struct kvm_vm *vm, uint32_t write_percent); void memstress_set_write_percent(struct kvm_vm *vm, uint32_t write_percent);
void memstress_set_random_seed(struct kvm_vm *vm, uint32_t random_seed);
void memstress_set_random_access(struct kvm_vm *vm, bool random_access); void memstress_set_random_access(struct kvm_vm *vm, bool random_access);
void memstress_start_vcpu_threads(int vcpus, void (*vcpu_fn)(struct memstress_vcpu_args *)); void memstress_start_vcpu_threads(int vcpus, void (*vcpu_fn)(struct memstress_vcpu_args *));
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#ifndef SELFTEST_KVM_UCALL_H #ifndef SELFTEST_KVM_UCALL_H
#define SELFTEST_KVM_UCALL_H #define SELFTEST_KVM_UCALL_H
#include "kvm_util_base.h" #include "kvm_util.h"
#define UCALL_EXIT_REASON KVM_EXIT_S390_SIEIC #define UCALL_EXIT_REASON KVM_EXIT_S390_SIEIC
......
...@@ -91,9 +91,28 @@ struct guest_random_state { ...@@ -91,9 +91,28 @@ struct guest_random_state {
uint32_t seed; uint32_t seed;
}; };
extern uint32_t guest_random_seed;
extern struct guest_random_state guest_rng;
struct guest_random_state new_guest_random_state(uint32_t seed); struct guest_random_state new_guest_random_state(uint32_t seed);
uint32_t guest_random_u32(struct guest_random_state *state); uint32_t guest_random_u32(struct guest_random_state *state);
static inline bool __guest_random_bool(struct guest_random_state *state,
uint8_t percent)
{
return (guest_random_u32(state) % 100) < percent;
}
static inline bool guest_random_bool(struct guest_random_state *state)
{
return __guest_random_bool(state, 50);
}
static inline uint64_t guest_random_u64(struct guest_random_state *state)
{
return ((uint64_t)guest_random_u32(state) << 32) | guest_random_u32(state);
}
enum vm_mem_backing_src_type { enum vm_mem_backing_src_type {
VM_MEM_SRC_ANONYMOUS, VM_MEM_SRC_ANONYMOUS,
VM_MEM_SRC_ANONYMOUS_THP, VM_MEM_SRC_ANONYMOUS_THP,
......
...@@ -5,9 +5,6 @@ ...@@ -5,9 +5,6 @@
* Copyright (C) 2018, Red Hat, Inc. * Copyright (C) 2018, Red Hat, Inc.
* Copyright (C) 2019-2022 Google LLC * Copyright (C) 2019-2022 Google LLC
*/ */
#define _GNU_SOURCE /* for pipe2 */
#include <inttypes.h> #include <inttypes.h>
#include <time.h> #include <time.h>
#include <pthread.h> #include <pthread.h>
......
...@@ -5,7 +5,16 @@ ...@@ -5,7 +5,16 @@
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include "kvm_util_types.h"
#include "test_util.h"
extern bool is_forced_emulation_enabled;
struct kvm_vm_arch { struct kvm_vm_arch {
vm_vaddr_t gdt;
vm_vaddr_t tss;
vm_vaddr_t idt;
uint64_t c_bit; uint64_t c_bit;
uint64_t s_bit; uint64_t s_bit;
int sev_fd; int sev_fd;
...@@ -20,4 +29,23 @@ static inline bool __vm_arch_has_protected_memory(struct kvm_vm_arch *arch) ...@@ -20,4 +29,23 @@ static inline bool __vm_arch_has_protected_memory(struct kvm_vm_arch *arch)
#define vm_arch_has_protected_memory(vm) \ #define vm_arch_has_protected_memory(vm) \
__vm_arch_has_protected_memory(&(vm)->arch) __vm_arch_has_protected_memory(&(vm)->arch)
#define vcpu_arch_put_guest(mem, __val) \
do { \
const typeof(mem) val = (__val); \
\
if (!is_forced_emulation_enabled || guest_random_bool(&guest_rng)) { \
(mem) = val; \
} else if (guest_random_bool(&guest_rng)) { \
__asm__ __volatile__(KVM_FEP "mov %1, %0" \
: "+m" (mem) \
: "r" (val) : "memory"); \
} else { \
uint64_t __old = READ_ONCE(mem); \
\
__asm__ __volatile__(KVM_FEP LOCK_PREFIX "cmpxchg %[new], %[ptr]" \
: [ptr] "+m" (mem), [old] "+a" (__old) \
: [new]"r" (val) : "memory", "cc"); \
} \
} while (0)
#endif // SELFTEST_KVM_UTIL_ARCH_H #endif // SELFTEST_KVM_UTIL_ARCH_H
...@@ -18,7 +18,8 @@ ...@@ -18,7 +18,8 @@
#include <linux/kvm_para.h> #include <linux/kvm_para.h>
#include <linux/stringify.h> #include <linux/stringify.h>
#include "../kvm_util.h" #include "kvm_util.h"
#include "ucall_common.h"
extern bool host_cpu_is_intel; extern bool host_cpu_is_intel;
extern bool host_cpu_is_amd; extern bool host_cpu_is_amd;
...@@ -1133,8 +1134,6 @@ struct idt_entry { ...@@ -1133,8 +1134,6 @@ struct idt_entry {
uint32_t offset2; uint32_t reserved; uint32_t offset2; uint32_t reserved;
}; };
void vm_init_descriptor_tables(struct kvm_vm *vm);
void vcpu_init_descriptor_tables(struct kvm_vcpu *vcpu);
void vm_install_exception_handler(struct kvm_vm *vm, int vector, void vm_install_exception_handler(struct kvm_vm *vm, int vector,
void (*handler)(struct ex_regs *)); void (*handler)(struct ex_regs *));
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#ifndef SELFTEST_KVM_UCALL_H #ifndef SELFTEST_KVM_UCALL_H
#define SELFTEST_KVM_UCALL_H #define SELFTEST_KVM_UCALL_H
#include "kvm_util_base.h" #include "kvm_util.h"
#define UCALL_EXIT_REASON KVM_EXIT_IO #define UCALL_EXIT_REASON KVM_EXIT_IO
......
...@@ -6,8 +6,6 @@ ...@@ -6,8 +6,6 @@
* *
* Test the fd-based interface for KVM statistics. * Test the fd-based interface for KVM statistics.
*/ */
#define _GNU_SOURCE /* for program_invocation_short_name */
#include <fcntl.h> #include <fcntl.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
......
...@@ -6,8 +6,6 @@ ...@@ -6,8 +6,6 @@
* *
* Test for KVM_CAP_MAX_VCPUS and KVM_CAP_MAX_VCPU_ID. * Test for KVM_CAP_MAX_VCPUS and KVM_CAP_MAX_VCPU_ID.
*/ */
#define _GNU_SOURCE /* for program_invocation_short_name */
#include <fcntl.h> #include <fcntl.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
......
...@@ -8,9 +8,6 @@ ...@@ -8,9 +8,6 @@
* page size have been pre-allocated on your system, if you are planning to * page size have been pre-allocated on your system, if you are planning to
* use hugepages to back the guest memory for testing. * use hugepages to back the guest memory for testing.
*/ */
#define _GNU_SOURCE /* for program_invocation_name */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <time.h> #include <time.h>
...@@ -21,6 +18,7 @@ ...@@ -21,6 +18,7 @@
#include "kvm_util.h" #include "kvm_util.h"
#include "processor.h" #include "processor.h"
#include "guest_modes.h" #include "guest_modes.h"
#include "ucall_common.h"
#define TEST_MEM_SLOT_INDEX 1 #define TEST_MEM_SLOT_INDEX 1
......
...@@ -11,6 +11,8 @@ ...@@ -11,6 +11,8 @@
#include "guest_modes.h" #include "guest_modes.h"
#include "kvm_util.h" #include "kvm_util.h"
#include "processor.h" #include "processor.h"
#include "ucall_common.h"
#include <linux/bitfield.h> #include <linux/bitfield.h>
#include <linux/sizes.h> #include <linux/sizes.h>
......
...@@ -4,9 +4,6 @@ ...@@ -4,9 +4,6 @@
* *
* Copyright (C) 2018, Google LLC. * Copyright (C) 2018, Google LLC.
*/ */
#define _GNU_SOURCE /* for getline(3) and strchrnul(3)*/
#include "test_util.h" #include "test_util.h"
#include <execinfo.h> #include <execinfo.h>
......
...@@ -4,11 +4,10 @@ ...@@ -4,11 +4,10 @@
* *
* Copyright (C) 2018, Google LLC. * Copyright (C) 2018, Google LLC.
*/ */
#define _GNU_SOURCE /* for program_invocation_name */
#include "test_util.h" #include "test_util.h"
#include "kvm_util.h" #include "kvm_util.h"
#include "processor.h" #include "processor.h"
#include "ucall_common.h"
#include <assert.h> #include <assert.h>
#include <sched.h> #include <sched.h>
...@@ -20,6 +19,9 @@ ...@@ -20,6 +19,9 @@
#define KVM_UTIL_MIN_PFN 2 #define KVM_UTIL_MIN_PFN 2
uint32_t guest_random_seed;
struct guest_random_state guest_rng;
static int vcpu_mmap_sz(void); 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)
...@@ -432,6 +434,10 @@ struct kvm_vm *__vm_create(struct vm_shape shape, uint32_t nr_runnable_vcpus, ...@@ -432,6 +434,10 @@ struct kvm_vm *__vm_create(struct vm_shape shape, uint32_t nr_runnable_vcpus,
slot0 = memslot2region(vm, 0); slot0 = memslot2region(vm, 0);
ucall_init(vm, slot0->region.guest_phys_addr + slot0->region.memory_size); ucall_init(vm, slot0->region.guest_phys_addr + slot0->region.memory_size);
pr_info("Random seed: 0x%x\n", guest_random_seed);
guest_rng = new_guest_random_state(guest_random_seed);
sync_global_to_guest(vm, guest_rng);
kvm_arch_vm_post_create(vm); kvm_arch_vm_post_create(vm);
return vm; return vm;
...@@ -2313,6 +2319,8 @@ void __attribute((constructor)) kvm_selftest_init(void) ...@@ -2313,6 +2319,8 @@ void __attribute((constructor)) kvm_selftest_init(void)
/* Tell stdout not to buffer its content. */ /* Tell stdout not to buffer its content. */
setbuf(stdout, NULL); setbuf(stdout, NULL);
guest_random_seed = random();
kvm_selftest_arch_init(); kvm_selftest_arch_init();
} }
......
...@@ -2,14 +2,13 @@ ...@@ -2,14 +2,13 @@
/* /*
* Copyright (C) 2020, Google LLC. * Copyright (C) 2020, Google LLC.
*/ */
#define _GNU_SOURCE
#include <inttypes.h> #include <inttypes.h>
#include <linux/bitmap.h> #include <linux/bitmap.h>
#include "kvm_util.h" #include "kvm_util.h"
#include "memstress.h" #include "memstress.h"
#include "processor.h" #include "processor.h"
#include "ucall_common.h"
struct memstress_args memstress_args; struct memstress_args memstress_args;
...@@ -56,7 +55,7 @@ void memstress_guest_code(uint32_t vcpu_idx) ...@@ -56,7 +55,7 @@ void memstress_guest_code(uint32_t vcpu_idx)
uint64_t page; uint64_t page;
int i; int i;
rand_state = new_guest_random_state(args->random_seed + vcpu_idx); rand_state = new_guest_random_state(guest_random_seed + vcpu_idx);
gva = vcpu_args->gva; gva = vcpu_args->gva;
pages = vcpu_args->pages; pages = vcpu_args->pages;
...@@ -76,7 +75,7 @@ void memstress_guest_code(uint32_t vcpu_idx) ...@@ -76,7 +75,7 @@ void memstress_guest_code(uint32_t vcpu_idx)
addr = gva + (page * args->guest_page_size); addr = gva + (page * args->guest_page_size);
if (guest_random_u32(&rand_state) % 100 < args->write_percent) if (__guest_random_bool(&rand_state, args->write_percent))
*(uint64_t *)addr = 0x0123456789ABCDEF; *(uint64_t *)addr = 0x0123456789ABCDEF;
else else
READ_ONCE(*(uint64_t *)addr); READ_ONCE(*(uint64_t *)addr);
...@@ -243,12 +242,6 @@ void memstress_set_write_percent(struct kvm_vm *vm, uint32_t write_percent) ...@@ -243,12 +242,6 @@ void memstress_set_write_percent(struct kvm_vm *vm, uint32_t write_percent)
sync_global_to_guest(vm, memstress_args.write_percent); sync_global_to_guest(vm, memstress_args.write_percent);
} }
void memstress_set_random_seed(struct kvm_vm *vm, uint32_t random_seed)
{
memstress_args.random_seed = random_seed;
sync_global_to_guest(vm, memstress_args.random_seed);
}
void memstress_set_random_access(struct kvm_vm *vm, bool random_access) void memstress_set_random_access(struct kvm_vm *vm, bool random_access)
{ {
memstress_args.random_access = random_access; memstress_args.random_access = random_access;
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "kvm_util.h" #include "kvm_util.h"
#include "processor.h" #include "processor.h"
#include "ucall_common.h"
#define DEFAULT_RISCV_GUEST_STACK_VADDR_MIN 0xac0000 #define DEFAULT_RISCV_GUEST_STACK_VADDR_MIN 0xac0000
......
...@@ -4,8 +4,6 @@ ...@@ -4,8 +4,6 @@
* *
* Copyright (C) 2020, Google LLC. * Copyright (C) 2020, Google LLC.
*/ */
#define _GNU_SOURCE
#include <stdio.h> #include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
#include <assert.h> #include <assert.h>
......
// SPDX-License-Identifier: GPL-2.0-only // SPDX-License-Identifier: GPL-2.0-only
#include "kvm_util.h"
#include "linux/types.h" #include "linux/types.h"
#include "linux/bitmap.h" #include "linux/bitmap.h"
#include "linux/atomic.h" #include "linux/atomic.h"
#include "kvm_util.h"
#include "ucall_common.h"
#define GUEST_UCALL_FAILED -1 #define GUEST_UCALL_FAILED -1
struct ucall_header { struct ucall_header {
......
...@@ -6,9 +6,6 @@ ...@@ -6,9 +6,6 @@
* Copyright (C) 2018, Red Hat, Inc. * Copyright (C) 2018, Red Hat, Inc.
* Copyright (C) 2019-2022 Google LLC * Copyright (C) 2019-2022 Google LLC
*/ */
#define _GNU_SOURCE /* for pipe2 */
#include <inttypes.h> #include <inttypes.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
......
// SPDX-License-Identifier: GPL-2.0-only // SPDX-License-Identifier: GPL-2.0-only
#define _GNU_SOURCE /* for program_invocation_short_name */
#include <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
......
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#define _GNU_SOURCE
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <pthread.h> #include <pthread.h>
......
...@@ -6,9 +6,6 @@ ...@@ -6,9 +6,6 @@
* Copyright (C) 2018, Red Hat, Inc. * Copyright (C) 2018, Red Hat, Inc.
* Copyright (C) 2020, Google, Inc. * Copyright (C) 2020, Google, Inc.
*/ */
#define _GNU_SOURCE /* for program_invocation_name */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <sys/syscall.h> #include <sys/syscall.h>
......
...@@ -7,13 +7,11 @@ ...@@ -7,13 +7,11 @@
* *
* Copyright (c) 2024, Intel Corporation. * Copyright (c) 2024, Intel Corporation.
*/ */
#define _GNU_SOURCE
#include "arch_timer.h" #include "arch_timer.h"
#include "kvm_util.h" #include "kvm_util.h"
#include "processor.h" #include "processor.h"
#include "timer_test.h" #include "timer_test.h"
#include "ucall_common.h"
static int timer_irq = IRQ_S_TIMER; static int timer_irq = IRQ_S_TIMER;
......
// SPDX-License-Identifier: GPL-2.0-only // SPDX-License-Identifier: GPL-2.0-only
#define _GNU_SOURCE /* for program_invocation_short_name */
/*
* Include rseq.c without _GNU_SOURCE defined, before including any headers, so
* that rseq.c is compiled with its configuration, not KVM selftests' config.
*/
#undef _GNU_SOURCE
#include "../rseq/rseq.c"
#define _GNU_SOURCE
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <pthread.h> #include <pthread.h>
...@@ -19,8 +27,7 @@ ...@@ -19,8 +27,7 @@
#include "kvm_util.h" #include "kvm_util.h"
#include "processor.h" #include "processor.h"
#include "test_util.h" #include "test_util.h"
#include "ucall_common.h"
#include "../rseq/rseq.c"
/* /*
* Any bug related to task migration is likely to be timing-dependent; perform * Any bug related to task migration is likely to be timing-dependent; perform
......
...@@ -7,8 +7,6 @@ ...@@ -7,8 +7,6 @@
* Authors: * Authors:
* Nico Boehr <nrb@linux.ibm.com> * Nico Boehr <nrb@linux.ibm.com>
*/ */
#define _GNU_SOURCE /* for program_invocation_short_name */
#include <fcntl.h> #include <fcntl.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
...@@ -18,6 +16,7 @@ ...@@ -18,6 +16,7 @@
#include "test_util.h" #include "test_util.h"
#include "kvm_util.h" #include "kvm_util.h"
#include "kselftest.h" #include "kselftest.h"
#include "ucall_common.h"
#define MAIN_PAGE_COUNT 512 #define MAIN_PAGE_COUNT 512
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "test_util.h" #include "test_util.h"
#include "kvm_util.h" #include "kvm_util.h"
#include "kselftest.h" #include "kselftest.h"
#include "ucall_common.h"
enum mop_target { enum mop_target {
LOGICAL, LOGICAL,
......
...@@ -10,8 +10,6 @@ ...@@ -10,8 +10,6 @@
* *
* Test expected behavior of the KVM_CAP_SYNC_REGS functionality. * Test expected behavior of the KVM_CAP_SYNC_REGS functionality.
*/ */
#define _GNU_SOURCE /* for program_invocation_short_name */
#include <fcntl.h> #include <fcntl.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "test_util.h" #include "test_util.h"
#include "kvm_util.h" #include "kvm_util.h"
#include "kselftest.h" #include "kselftest.h"
#include "ucall_common.h"
#define PAGE_SHIFT 12 #define PAGE_SHIFT 12
#define PAGE_SIZE (1 << PAGE_SHIFT) #define PAGE_SIZE (1 << PAGE_SHIFT)
......
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#define _GNU_SOURCE /* for program_invocation_short_name */
#include <fcntl.h> #include <fcntl.h>
#include <pthread.h> #include <pthread.h>
#include <sched.h> #include <sched.h>
...@@ -221,8 +220,20 @@ static void test_move_memory_region(void) ...@@ -221,8 +220,20 @@ static void test_move_memory_region(void)
static void guest_code_delete_memory_region(void) static void guest_code_delete_memory_region(void)
{ {
struct desc_ptr idt;
uint64_t val; uint64_t val;
/*
* Clobber the IDT so that a #PF due to the memory region being deleted
* escalates to triple-fault shutdown. Because the memory region is
* deleted, there will be no valid mappings. As a result, KVM will
* repeatedly intercepts the state-2 page fault that occurs when trying
* to vector the guest's #PF. I.e. trying to actually handle the #PF
* in the guest will never succeed, and so isn't an option.
*/
memset(&idt, 0, sizeof(idt));
__asm__ __volatile__("lidt %0" :: "m"(idt));
GUEST_SYNC(0); GUEST_SYNC(0);
/* Spin until the memory region is deleted. */ /* Spin until the memory region is deleted. */
......
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
* *
* Copyright (C) 2020, Red Hat, Inc. * Copyright (C) 2020, Red Hat, Inc.
*/ */
#define _GNU_SOURCE
#include <stdio.h> #include <stdio.h>
#include <time.h> #include <time.h>
#include <sched.h> #include <sched.h>
...@@ -20,6 +19,7 @@ ...@@ -20,6 +19,7 @@
#include "test_util.h" #include "test_util.h"
#include "kvm_util.h" #include "kvm_util.h"
#include "processor.h" #include "processor.h"
#include "ucall_common.h"
#define NR_VCPUS 4 #define NR_VCPUS 4
#define ST_GPA_BASE (1 << 30) #define ST_GPA_BASE (1 << 30)
......
...@@ -6,8 +6,6 @@ ...@@ -6,8 +6,6 @@
* *
* Tests for amx #NM exception and save/restore. * Tests for amx #NM exception and save/restore.
*/ */
#define _GNU_SOURCE /* for program_invocation_short_name */
#include <fcntl.h> #include <fcntl.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
...@@ -246,8 +244,6 @@ int main(int argc, char *argv[]) ...@@ -246,8 +244,6 @@ int main(int argc, char *argv[])
vcpu_regs_get(vcpu, &regs1); vcpu_regs_get(vcpu, &regs1);
/* Register #NM handler */ /* Register #NM handler */
vm_init_descriptor_tables(vm);
vcpu_init_descriptor_tables(vcpu);
vm_install_exception_handler(vm, NM_VECTOR, guest_nm_handler); vm_install_exception_handler(vm, NM_VECTOR, guest_nm_handler);
/* amx cfg for guest_code */ /* amx cfg for guest_code */
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "test_util.h" #include "test_util.h"
#include "memstress.h" #include "memstress.h"
#include "guest_modes.h" #include "guest_modes.h"
#include "ucall_common.h"
#define VCPUS 2 #define VCPUS 2
#define SLOTS 2 #define SLOTS 2
......
...@@ -4,12 +4,9 @@ ...@@ -4,12 +4,9 @@
* *
* Test for KVM_CAP_EXIT_ON_EMULATION_FAILURE. * Test for KVM_CAP_EXIT_ON_EMULATION_FAILURE.
*/ */
#define _GNU_SOURCE /* for program_invocation_short_name */
#include "flds_emulation.h" #include "flds_emulation.h"
#include "test_util.h" #include "test_util.h"
#include "ucall_common.h"
#define MMIO_GPA 0x700000000 #define MMIO_GPA 0x700000000
#define MMIO_GVA MMIO_GPA #define MMIO_GVA MMIO_GPA
......
...@@ -110,8 +110,6 @@ static void test_fix_hypercall(struct kvm_vcpu *vcpu, bool disable_quirk) ...@@ -110,8 +110,6 @@ static void test_fix_hypercall(struct kvm_vcpu *vcpu, bool disable_quirk)
{ {
struct kvm_vm *vm = vcpu->vm; struct kvm_vm *vm = vcpu->vm;
vm_init_descriptor_tables(vm);
vcpu_init_descriptor_tables(vcpu);
vm_install_exception_handler(vcpu->vm, UD_VECTOR, guest_ud_handler); vm_install_exception_handler(vcpu->vm, UD_VECTOR, guest_ud_handler);
if (disable_quirk) if (disable_quirk)
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
/* /*
* Copyright (C) 2023, Google LLC. * Copyright (C) 2023, Google LLC.
*/ */
#define _GNU_SOURCE /* for program_invocation_short_name */
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include "test_util.h" #include "test_util.h"
......
...@@ -7,8 +7,6 @@ ...@@ -7,8 +7,6 @@
* This work is licensed under the terms of the GNU GPL, version 2. * This work is licensed under the terms of the GNU GPL, version 2.
* *
*/ */
#define _GNU_SOURCE /* for program_invocation_short_name */
#include <fcntl.h> #include <fcntl.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
......
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
* *
* Tests for Enlightened VMCS, including nested guest state. * Tests for Enlightened VMCS, including nested guest state.
*/ */
#define _GNU_SOURCE /* for program_invocation_short_name */
#include <fcntl.h> #include <fcntl.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
...@@ -258,8 +257,6 @@ int main(int argc, char *argv[]) ...@@ -258,8 +257,6 @@ int main(int argc, char *argv[])
vcpu_args_set(vcpu, 3, vmx_pages_gva, hv_pages_gva, addr_gva2gpa(vm, hcall_page)); vcpu_args_set(vcpu, 3, vmx_pages_gva, hv_pages_gva, addr_gva2gpa(vm, hcall_page));
vcpu_set_msr(vcpu, HV_X64_MSR_VP_INDEX, vcpu->id); vcpu_set_msr(vcpu, HV_X64_MSR_VP_INDEX, vcpu->id);
vm_init_descriptor_tables(vm);
vcpu_init_descriptor_tables(vcpu);
vm_install_exception_handler(vm, UD_VECTOR, guest_ud_handler); vm_install_exception_handler(vm, UD_VECTOR, guest_ud_handler);
vm_install_exception_handler(vm, NMI_VECTOR, guest_nmi_handler); vm_install_exception_handler(vm, NMI_VECTOR, guest_nmi_handler);
......
...@@ -156,9 +156,6 @@ static void guest_test_msrs_access(void) ...@@ -156,9 +156,6 @@ static void guest_test_msrs_access(void)
vcpu_init_cpuid(vcpu, prev_cpuid); vcpu_init_cpuid(vcpu, prev_cpuid);
} }
vm_init_descriptor_tables(vm);
vcpu_init_descriptor_tables(vcpu);
/* TODO: Make this entire test easier to maintain. */ /* TODO: Make this entire test easier to maintain. */
if (stage >= 21) if (stage >= 21)
vcpu_enable_cap(vcpu, KVM_CAP_HYPERV_SYNIC2, 0); vcpu_enable_cap(vcpu, KVM_CAP_HYPERV_SYNIC2, 0);
...@@ -532,9 +529,6 @@ static void guest_test_hcalls_access(void) ...@@ -532,9 +529,6 @@ static void guest_test_hcalls_access(void)
while (true) { while (true) {
vm = vm_create_with_one_vcpu(&vcpu, guest_hcall); vm = vm_create_with_one_vcpu(&vcpu, guest_hcall);
vm_init_descriptor_tables(vm);
vcpu_init_descriptor_tables(vcpu);
/* Hypercall input/output */ /* Hypercall input/output */
hcall_page = vm_vaddr_alloc_pages(vm, 2); hcall_page = vm_vaddr_alloc_pages(vm, 2);
memset(addr_gva2hva(vm, hcall_page), 0x0, 2 * getpagesize()); memset(addr_gva2hva(vm, hcall_page), 0x0, 2 * getpagesize());
......
...@@ -5,8 +5,6 @@ ...@@ -5,8 +5,6 @@
* Copyright (C) 2022, Red Hat, Inc. * Copyright (C) 2022, Red Hat, Inc.
* *
*/ */
#define _GNU_SOURCE /* for program_invocation_short_name */
#include <pthread.h> #include <pthread.h>
#include <inttypes.h> #include <inttypes.h>
...@@ -256,16 +254,13 @@ int main(int argc, char *argv[]) ...@@ -256,16 +254,13 @@ int main(int argc, char *argv[])
hcall_page = vm_vaddr_alloc_pages(vm, 2); hcall_page = vm_vaddr_alloc_pages(vm, 2);
memset(addr_gva2hva(vm, hcall_page), 0x0, 2 * getpagesize()); memset(addr_gva2hva(vm, hcall_page), 0x0, 2 * getpagesize());
vm_init_descriptor_tables(vm);
vcpu[1] = vm_vcpu_add(vm, RECEIVER_VCPU_ID_1, receiver_code); vcpu[1] = vm_vcpu_add(vm, RECEIVER_VCPU_ID_1, receiver_code);
vcpu_init_descriptor_tables(vcpu[1]);
vcpu_args_set(vcpu[1], 2, hcall_page, addr_gva2gpa(vm, hcall_page)); vcpu_args_set(vcpu[1], 2, hcall_page, addr_gva2gpa(vm, hcall_page));
vcpu_set_msr(vcpu[1], HV_X64_MSR_VP_INDEX, RECEIVER_VCPU_ID_1); vcpu_set_msr(vcpu[1], HV_X64_MSR_VP_INDEX, RECEIVER_VCPU_ID_1);
vcpu_set_hv_cpuid(vcpu[1]); vcpu_set_hv_cpuid(vcpu[1]);
vcpu[2] = vm_vcpu_add(vm, RECEIVER_VCPU_ID_2, receiver_code); vcpu[2] = vm_vcpu_add(vm, RECEIVER_VCPU_ID_2, receiver_code);
vcpu_init_descriptor_tables(vcpu[2]);
vcpu_args_set(vcpu[2], 2, hcall_page, addr_gva2gpa(vm, hcall_page)); vcpu_args_set(vcpu[2], 2, hcall_page, addr_gva2gpa(vm, hcall_page));
vcpu_set_msr(vcpu[2], HV_X64_MSR_VP_INDEX, RECEIVER_VCPU_ID_2); vcpu_set_msr(vcpu[2], HV_X64_MSR_VP_INDEX, RECEIVER_VCPU_ID_2);
vcpu_set_hv_cpuid(vcpu[2]); vcpu_set_hv_cpuid(vcpu[2]);
......
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
* *
* Tests for Hyper-V extensions to SVM. * Tests for Hyper-V extensions to SVM.
*/ */
#define _GNU_SOURCE /* for program_invocation_short_name */
#include <fcntl.h> #include <fcntl.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
......
...@@ -5,8 +5,6 @@ ...@@ -5,8 +5,6 @@
* Copyright (C) 2022, Red Hat, Inc. * Copyright (C) 2022, Red Hat, Inc.
* *
*/ */
#define _GNU_SOURCE /* for program_invocation_short_name */
#include <asm/barrier.h> #include <asm/barrier.h>
#include <pthread.h> #include <pthread.h>
#include <inttypes.h> #include <inttypes.h>
......
...@@ -183,9 +183,6 @@ int main(void) ...@@ -183,9 +183,6 @@ int main(void)
vcpu_clear_cpuid_entry(vcpu, KVM_CPUID_FEATURES); vcpu_clear_cpuid_entry(vcpu, KVM_CPUID_FEATURES);
vm_init_descriptor_tables(vm);
vcpu_init_descriptor_tables(vcpu);
enter_guest(vcpu); enter_guest(vcpu);
kvm_vm_free(vm); kvm_vm_free(vm);
......
...@@ -81,9 +81,6 @@ int main(int argc, char *argv[]) ...@@ -81,9 +81,6 @@ int main(int argc, char *argv[])
vm = vm_create_with_one_vcpu(&vcpu, guest_code); vm = vm_create_with_one_vcpu(&vcpu, guest_code);
vcpu_clear_cpuid_feature(vcpu, X86_FEATURE_MWAIT); vcpu_clear_cpuid_feature(vcpu, X86_FEATURE_MWAIT);
vm_init_descriptor_tables(vm);
vcpu_init_descriptor_tables(vcpu);
while (1) { while (1) {
vcpu_run(vcpu); vcpu_run(vcpu);
TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO); TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO);
......
// SPDX-License-Identifier: GPL-2.0-only // SPDX-License-Identifier: GPL-2.0-only
#define _GNU_SOURCE /* for program_invocation_short_name */
#include "test_util.h" #include "test_util.h"
#include "kvm_util.h" #include "kvm_util.h"
#include "processor.h" #include "processor.h"
......
...@@ -5,9 +5,6 @@ ...@@ -5,9 +5,6 @@
* *
* Copyright (C) 2022, Google LLC. * Copyright (C) 2022, Google LLC.
*/ */
#define _GNU_SOURCE
#include <fcntl.h> #include <fcntl.h>
#include <stdint.h> #include <stdint.h>
#include <time.h> #include <time.h>
......
...@@ -9,8 +9,6 @@ ...@@ -9,8 +9,6 @@
* Verifies expected behavior of controlling guest access to * Verifies expected behavior of controlling guest access to
* MSR_PLATFORM_INFO. * MSR_PLATFORM_INFO.
*/ */
#define _GNU_SOURCE /* for program_invocation_short_name */
#include <fcntl.h> #include <fcntl.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
...@@ -26,36 +24,18 @@ ...@@ -26,36 +24,18 @@
static void guest_code(void) static void guest_code(void)
{ {
uint64_t msr_platform_info; uint64_t msr_platform_info;
uint8_t vector;
for (;;) { GUEST_SYNC(true);
msr_platform_info = rdmsr(MSR_PLATFORM_INFO); msr_platform_info = rdmsr(MSR_PLATFORM_INFO);
GUEST_SYNC(msr_platform_info); GUEST_ASSERT_EQ(msr_platform_info & MSR_PLATFORM_INFO_MAX_TURBO_RATIO,
asm volatile ("inc %r11");
}
}
static void test_msr_platform_info_enabled(struct kvm_vcpu *vcpu)
{
struct ucall uc;
vm_enable_cap(vcpu->vm, KVM_CAP_MSR_PLATFORM_INFO, true);
vcpu_run(vcpu);
TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO);
get_ucall(vcpu, &uc);
TEST_ASSERT(uc.cmd == UCALL_SYNC,
"Received ucall other than UCALL_SYNC: %lu", uc.cmd);
TEST_ASSERT((uc.args[1] & MSR_PLATFORM_INFO_MAX_TURBO_RATIO) ==
MSR_PLATFORM_INFO_MAX_TURBO_RATIO,
"Expected MSR_PLATFORM_INFO to have max turbo ratio mask: %i.",
MSR_PLATFORM_INFO_MAX_TURBO_RATIO); MSR_PLATFORM_INFO_MAX_TURBO_RATIO);
}
static void test_msr_platform_info_disabled(struct kvm_vcpu *vcpu) GUEST_SYNC(false);
{ vector = rdmsr_safe(MSR_PLATFORM_INFO, &msr_platform_info);
vm_enable_cap(vcpu->vm, KVM_CAP_MSR_PLATFORM_INFO, false); GUEST_ASSERT_EQ(vector, GP_VECTOR);
vcpu_run(vcpu);
TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_SHUTDOWN); GUEST_DONE();
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])
...@@ -63,6 +43,7 @@ int main(int argc, char *argv[]) ...@@ -63,6 +43,7 @@ int main(int argc, char *argv[])
struct kvm_vcpu *vcpu; struct kvm_vcpu *vcpu;
struct kvm_vm *vm; struct kvm_vm *vm;
uint64_t msr_platform_info; uint64_t msr_platform_info;
struct ucall uc;
TEST_REQUIRE(kvm_has_cap(KVM_CAP_MSR_PLATFORM_INFO)); TEST_REQUIRE(kvm_has_cap(KVM_CAP_MSR_PLATFORM_INFO));
...@@ -71,8 +52,26 @@ int main(int argc, char *argv[]) ...@@ -71,8 +52,26 @@ int main(int argc, char *argv[])
msr_platform_info = vcpu_get_msr(vcpu, MSR_PLATFORM_INFO); msr_platform_info = vcpu_get_msr(vcpu, MSR_PLATFORM_INFO);
vcpu_set_msr(vcpu, MSR_PLATFORM_INFO, vcpu_set_msr(vcpu, MSR_PLATFORM_INFO,
msr_platform_info | MSR_PLATFORM_INFO_MAX_TURBO_RATIO); msr_platform_info | MSR_PLATFORM_INFO_MAX_TURBO_RATIO);
test_msr_platform_info_enabled(vcpu);
test_msr_platform_info_disabled(vcpu); for (;;) {
vcpu_run(vcpu);
TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO);
switch (get_ucall(vcpu, &uc)) {
case UCALL_SYNC:
vm_enable_cap(vm, KVM_CAP_MSR_PLATFORM_INFO, uc.args[1]);
break;
case UCALL_DONE:
goto done;
case UCALL_ABORT:
REPORT_GUEST_ASSERT(uc);
default:
TEST_FAIL("Unexpected ucall %lu", uc.cmd);
break;
}
}
done:
vcpu_set_msr(vcpu, MSR_PLATFORM_INFO, msr_platform_info); vcpu_set_msr(vcpu, MSR_PLATFORM_INFO, msr_platform_info);
kvm_vm_free(vm); kvm_vm_free(vm);
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
/* /*
* Copyright (C) 2023, Tencent, Inc. * Copyright (C) 2023, Tencent, Inc.
*/ */
#define _GNU_SOURCE /* for program_invocation_short_name */
#include <x86intrin.h> #include <x86intrin.h>
#include "pmu.h" #include "pmu.h"
...@@ -21,7 +19,6 @@ ...@@ -21,7 +19,6 @@
static uint8_t kvm_pmu_version; static uint8_t kvm_pmu_version;
static bool kvm_has_perf_caps; static bool kvm_has_perf_caps;
static bool is_forced_emulation_enabled;
static struct kvm_vm *pmu_vm_create_with_one_vcpu(struct kvm_vcpu **vcpu, static struct kvm_vm *pmu_vm_create_with_one_vcpu(struct kvm_vcpu **vcpu,
void *guest_code, void *guest_code,
...@@ -31,11 +28,7 @@ static struct kvm_vm *pmu_vm_create_with_one_vcpu(struct kvm_vcpu **vcpu, ...@@ -31,11 +28,7 @@ static struct kvm_vm *pmu_vm_create_with_one_vcpu(struct kvm_vcpu **vcpu,
struct kvm_vm *vm; struct kvm_vm *vm;
vm = vm_create_with_one_vcpu(vcpu, guest_code); vm = vm_create_with_one_vcpu(vcpu, guest_code);
vm_init_descriptor_tables(vm);
vcpu_init_descriptor_tables(*vcpu);
sync_global_to_guest(vm, kvm_pmu_version); sync_global_to_guest(vm, kvm_pmu_version);
sync_global_to_guest(vm, is_forced_emulation_enabled);
/* /*
* Set PERF_CAPABILITIES before PMU version as KVM disallows enabling * Set PERF_CAPABILITIES before PMU version as KVM disallows enabling
...@@ -630,7 +623,6 @@ int main(int argc, char *argv[]) ...@@ -630,7 +623,6 @@ int main(int argc, char *argv[])
kvm_pmu_version = kvm_cpu_property(X86_PROPERTY_PMU_VERSION); kvm_pmu_version = kvm_cpu_property(X86_PROPERTY_PMU_VERSION);
kvm_has_perf_caps = kvm_cpu_has(X86_FEATURE_PDCM); kvm_has_perf_caps = kvm_cpu_has(X86_FEATURE_PDCM);
is_forced_emulation_enabled = kvm_is_forced_emulation_enabled();
test_intel_counters(); test_intel_counters();
......
...@@ -9,9 +9,6 @@ ...@@ -9,9 +9,6 @@
* Verifies the expected behavior of allow lists and deny lists for * Verifies the expected behavior of allow lists and deny lists for
* virtual PMU events. * virtual PMU events.
*/ */
#define _GNU_SOURCE /* for program_invocation_short_name */
#include "kvm_util.h" #include "kvm_util.h"
#include "pmu.h" #include "pmu.h"
#include "processor.h" #include "processor.h"
...@@ -337,9 +334,6 @@ static void test_pmu_config_disable(void (*guest_code)(void)) ...@@ -337,9 +334,6 @@ static void test_pmu_config_disable(void (*guest_code)(void))
vm_enable_cap(vm, KVM_CAP_PMU_CAPABILITY, KVM_PMU_CAP_DISABLE); vm_enable_cap(vm, KVM_CAP_PMU_CAPABILITY, KVM_PMU_CAP_DISABLE);
vcpu = vm_vcpu_add(vm, 0, guest_code); vcpu = vm_vcpu_add(vm, 0, guest_code);
vm_init_descriptor_tables(vm);
vcpu_init_descriptor_tables(vcpu);
TEST_ASSERT(!sanity_check_pmu(vcpu), TEST_ASSERT(!sanity_check_pmu(vcpu),
"Guest should not be able to use disabled PMU."); "Guest should not be able to use disabled PMU.");
...@@ -876,9 +870,6 @@ int main(int argc, char *argv[]) ...@@ -876,9 +870,6 @@ int main(int argc, char *argv[])
vm = vm_create_with_one_vcpu(&vcpu, guest_code); vm = vm_create_with_one_vcpu(&vcpu, guest_code);
vm_init_descriptor_tables(vm);
vcpu_init_descriptor_tables(vcpu);
TEST_REQUIRE(sanity_check_pmu(vcpu)); TEST_REQUIRE(sanity_check_pmu(vcpu));
if (use_amd_pmu()) if (use_amd_pmu())
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
/* /*
* Copyright (C) 2022, Google LLC. * Copyright (C) 2022, Google LLC.
*/ */
#define _GNU_SOURCE /* for program_invocation_short_name */
#include <fcntl.h> #include <fcntl.h>
#include <limits.h> #include <limits.h>
#include <pthread.h> #include <pthread.h>
......
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
* *
* Copyright (C) 2020, Red Hat, Inc. * Copyright (C) 2020, Red Hat, Inc.
*/ */
#define _GNU_SOURCE /* for program_invocation_name */
#include <fcntl.h> #include <fcntl.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
......
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
* That bug allowed a user-mode program that called the KVM_SET_SREGS * That bug allowed a user-mode program that called the KVM_SET_SREGS
* ioctl to put a VCPU's local APIC into an invalid state. * ioctl to put a VCPU's local APIC into an invalid state.
*/ */
#define _GNU_SOURCE /* for program_invocation_short_name */
#include <fcntl.h> #include <fcntl.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
......
...@@ -5,9 +5,6 @@ ...@@ -5,9 +5,6 @@
* Test that KVM emulates instructions in response to EPT violations when * Test that KVM emulates instructions in response to EPT violations when
* allow_smaller_maxphyaddr is enabled and guest.MAXPHYADDR < host.MAXPHYADDR. * allow_smaller_maxphyaddr is enabled and guest.MAXPHYADDR < host.MAXPHYADDR.
*/ */
#define _GNU_SOURCE /* for program_invocation_short_name */
#include "flds_emulation.h" #include "flds_emulation.h"
#include "test_util.h" #include "test_util.h"
...@@ -60,9 +57,6 @@ int main(int argc, char *argv[]) ...@@ -60,9 +57,6 @@ int main(int argc, char *argv[])
vm = vm_create_with_one_vcpu(&vcpu, guest_code); vm = vm_create_with_one_vcpu(&vcpu, guest_code);
vcpu_args_set(vcpu, 1, kvm_is_tdp_enabled()); vcpu_args_set(vcpu, 1, kvm_is_tdp_enabled());
vm_init_descriptor_tables(vm);
vcpu_init_descriptor_tables(vcpu);
vcpu_set_cpuid_property(vcpu, X86_PROPERTY_MAX_PHY_ADDR, MAXPHYADDR); vcpu_set_cpuid_property(vcpu, X86_PROPERTY_MAX_PHY_ADDR, MAXPHYADDR);
rc = kvm_check_cap(KVM_CAP_EXIT_ON_EMULATION_FAILURE); rc = kvm_check_cap(KVM_CAP_EXIT_ON_EMULATION_FAILURE);
......
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
* *
* Tests for SMM. * Tests for SMM.
*/ */
#define _GNU_SOURCE /* for program_invocation_short_name */
#include <fcntl.h> #include <fcntl.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
* *
* Tests for vCPU state save/restore, including nested guest state. * Tests for vCPU state save/restore, including nested guest state.
*/ */
#define _GNU_SOURCE /* for program_invocation_short_name */
#include <fcntl.h> #include <fcntl.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
......
...@@ -93,9 +93,6 @@ int main(int argc, char *argv[]) ...@@ -93,9 +93,6 @@ int main(int argc, char *argv[])
vm = vm_create_with_one_vcpu(&vcpu, l1_guest_code); vm = vm_create_with_one_vcpu(&vcpu, l1_guest_code);
vm_init_descriptor_tables(vm);
vcpu_init_descriptor_tables(vcpu);
vm_install_exception_handler(vm, VINTR_IRQ_NUMBER, vintr_irq_handler); vm_install_exception_handler(vm, VINTR_IRQ_NUMBER, vintr_irq_handler);
vm_install_exception_handler(vm, INTR_IRQ_NUMBER, intr_irq_handler); vm_install_exception_handler(vm, INTR_IRQ_NUMBER, intr_irq_handler);
......
...@@ -48,12 +48,9 @@ int main(int argc, char *argv[]) ...@@ -48,12 +48,9 @@ int main(int argc, char *argv[])
TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_SVM)); TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_SVM));
vm = vm_create_with_one_vcpu(&vcpu, l1_guest_code); vm = vm_create_with_one_vcpu(&vcpu, l1_guest_code);
vm_init_descriptor_tables(vm);
vcpu_init_descriptor_tables(vcpu);
vcpu_alloc_svm(vm, &svm_gva); vcpu_alloc_svm(vm, &svm_gva);
vcpu_args_set(vcpu, 2, svm_gva, vm->idt); vcpu_args_set(vcpu, 2, svm_gva, vm->arch.idt);
vcpu_run(vcpu); vcpu_run(vcpu);
TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_SHUTDOWN); TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_SHUTDOWN);
......
...@@ -152,9 +152,6 @@ static void run_test(bool is_nmi) ...@@ -152,9 +152,6 @@ static void run_test(bool is_nmi)
vm = vm_create_with_one_vcpu(&vcpu, l1_guest_code); vm = vm_create_with_one_vcpu(&vcpu, l1_guest_code);
vm_init_descriptor_tables(vm);
vcpu_init_descriptor_tables(vcpu);
vm_install_exception_handler(vm, NMI_VECTOR, guest_nmi_handler); vm_install_exception_handler(vm, NMI_VECTOR, guest_nmi_handler);
vm_install_exception_handler(vm, BP_VECTOR, guest_bp_handler); vm_install_exception_handler(vm, BP_VECTOR, guest_bp_handler);
vm_install_exception_handler(vm, INT_NR, guest_int_handler); vm_install_exception_handler(vm, INT_NR, guest_int_handler);
...@@ -166,7 +163,7 @@ static void run_test(bool is_nmi) ...@@ -166,7 +163,7 @@ static void run_test(bool is_nmi)
idt_alt_vm = vm_vaddr_alloc_page(vm); idt_alt_vm = vm_vaddr_alloc_page(vm);
idt_alt = addr_gva2hva(vm, idt_alt_vm); idt_alt = addr_gva2hva(vm, idt_alt_vm);
idt = addr_gva2hva(vm, vm->idt); idt = addr_gva2hva(vm, vm->arch.idt);
memcpy(idt_alt, idt, getpagesize()); memcpy(idt_alt, idt, getpagesize());
} else { } else {
idt_alt_vm = 0; idt_alt_vm = 0;
......
...@@ -8,8 +8,6 @@ ...@@ -8,8 +8,6 @@
* including requesting an invalid register set, updates to/from values * including requesting an invalid register set, updates to/from values
* in kvm_run.s.regs when kvm_valid_regs and kvm_dirty_regs are toggled. * in kvm_run.s.regs when kvm_valid_regs and kvm_dirty_regs are toggled.
*/ */
#define _GNU_SOURCE /* for program_invocation_short_name */
#include <fcntl.h> #include <fcntl.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
......
...@@ -17,14 +17,11 @@ ...@@ -17,14 +17,11 @@
* delivered into the guest or not. * delivered into the guest or not.
* *
*/ */
#define _GNU_SOURCE /* for program_invocation_short_name */
#include <pthread.h> #include <pthread.h>
#include <inttypes.h> #include <inttypes.h>
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
#include "kvm_util_base.h"
#include "kvm_util.h" #include "kvm_util.h"
#include "mce.h" #include "mce.h"
#include "processor.h" #include "processor.h"
...@@ -285,10 +282,6 @@ int main(int argc, char *argv[]) ...@@ -285,10 +282,6 @@ int main(int argc, char *argv[])
cmcidis_vcpu = create_vcpu_with_mce_cap(vm, 1, false, cmci_disabled_guest_code); cmcidis_vcpu = create_vcpu_with_mce_cap(vm, 1, false, cmci_disabled_guest_code);
cmci_vcpu = create_vcpu_with_mce_cap(vm, 2, true, cmci_enabled_guest_code); cmci_vcpu = create_vcpu_with_mce_cap(vm, 2, true, cmci_enabled_guest_code);
vm_init_descriptor_tables(vm);
vcpu_init_descriptor_tables(ucna_vcpu);
vcpu_init_descriptor_tables(cmcidis_vcpu);
vcpu_init_descriptor_tables(cmci_vcpu);
vm_install_exception_handler(vm, CMCI_VECTOR, guest_cmci_handler); vm_install_exception_handler(vm, CMCI_VECTOR, guest_cmci_handler);
vm_install_exception_handler(vm, GP_VECTOR, guest_gp_handler); vm_install_exception_handler(vm, GP_VECTOR, guest_gp_handler);
......
...@@ -4,8 +4,6 @@ ...@@ -4,8 +4,6 @@
* *
* Tests for exiting into userspace on registered MSRs * Tests for exiting into userspace on registered MSRs
*/ */
#define _GNU_SOURCE /* for program_invocation_short_name */
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include "kvm_test_harness.h" #include "kvm_test_harness.h"
...@@ -13,8 +11,6 @@ ...@@ -13,8 +11,6 @@
#include "kvm_util.h" #include "kvm_util.h"
#include "vmx.h" #include "vmx.h"
static bool fep_available;
#define MSR_NON_EXISTENT 0x474f4f00 #define MSR_NON_EXISTENT 0x474f4f00
static u64 deny_bits = 0; static u64 deny_bits = 0;
...@@ -258,7 +254,7 @@ static void guest_code_filter_allow(void) ...@@ -258,7 +254,7 @@ static void guest_code_filter_allow(void)
GUEST_ASSERT(data == 2); GUEST_ASSERT(data == 2);
GUEST_ASSERT(guest_exception_count == 0); GUEST_ASSERT(guest_exception_count == 0);
if (fep_available) { if (is_forced_emulation_enabled) {
/* Let userspace know we aren't done. */ /* Let userspace know we aren't done. */
GUEST_SYNC(0); GUEST_SYNC(0);
...@@ -520,8 +516,6 @@ KVM_ONE_VCPU_TEST(user_msr, msr_filter_allow, guest_code_filter_allow) ...@@ -520,8 +516,6 @@ KVM_ONE_VCPU_TEST(user_msr, msr_filter_allow, guest_code_filter_allow)
uint64_t cmd; uint64_t cmd;
int rc; int rc;
sync_global_to_guest(vm, fep_available);
rc = kvm_check_cap(KVM_CAP_X86_USER_SPACE_MSR); rc = kvm_check_cap(KVM_CAP_X86_USER_SPACE_MSR);
TEST_ASSERT(rc, "KVM_CAP_X86_USER_SPACE_MSR is available"); TEST_ASSERT(rc, "KVM_CAP_X86_USER_SPACE_MSR is available");
vm_enable_cap(vm, KVM_CAP_X86_USER_SPACE_MSR, KVM_MSR_EXIT_REASON_FILTER); vm_enable_cap(vm, KVM_CAP_X86_USER_SPACE_MSR, KVM_MSR_EXIT_REASON_FILTER);
...@@ -531,9 +525,6 @@ KVM_ONE_VCPU_TEST(user_msr, msr_filter_allow, guest_code_filter_allow) ...@@ -531,9 +525,6 @@ KVM_ONE_VCPU_TEST(user_msr, msr_filter_allow, guest_code_filter_allow)
vm_ioctl(vm, KVM_X86_SET_MSR_FILTER, &filter_allow); vm_ioctl(vm, KVM_X86_SET_MSR_FILTER, &filter_allow);
vm_init_descriptor_tables(vm);
vcpu_init_descriptor_tables(vcpu);
vm_install_exception_handler(vm, GP_VECTOR, guest_gp_handler); vm_install_exception_handler(vm, GP_VECTOR, guest_gp_handler);
/* Process guest code userspace exits. */ /* Process guest code userspace exits. */
...@@ -551,7 +542,7 @@ KVM_ONE_VCPU_TEST(user_msr, msr_filter_allow, guest_code_filter_allow) ...@@ -551,7 +542,7 @@ KVM_ONE_VCPU_TEST(user_msr, msr_filter_allow, guest_code_filter_allow)
vcpu_run(vcpu); vcpu_run(vcpu);
cmd = process_ucall(vcpu); cmd = process_ucall(vcpu);
if (fep_available) { if (is_forced_emulation_enabled) {
TEST_ASSERT_EQ(cmd, UCALL_SYNC); TEST_ASSERT_EQ(cmd, UCALL_SYNC);
vm_install_exception_handler(vm, GP_VECTOR, guest_fep_gp_handler); vm_install_exception_handler(vm, GP_VECTOR, guest_fep_gp_handler);
...@@ -774,7 +765,5 @@ KVM_ONE_VCPU_TEST(user_msr, user_exit_msr_flags, NULL) ...@@ -774,7 +765,5 @@ KVM_ONE_VCPU_TEST(user_msr, user_exit_msr_flags, NULL)
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
fep_available = kvm_is_forced_emulation_enabled();
return test_harness_run(argc, argv); return test_harness_run(argc, argv);
} }
...@@ -4,9 +4,6 @@ ...@@ -4,9 +4,6 @@
* *
* Copyright (C) 2018, Red Hat, Inc. * Copyright (C) 2018, Red Hat, Inc.
*/ */
#define _GNU_SOURCE /* for program_invocation_name */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <linux/bitmap.h> #include <linux/bitmap.h>
......
...@@ -115,9 +115,6 @@ int main(int argc, char *argv[]) ...@@ -115,9 +115,6 @@ int main(int argc, char *argv[])
vm = vm_create_with_one_vcpu(&vcpu, guest_code); vm = vm_create_with_one_vcpu(&vcpu, guest_code);
get_set_sigalrm_vcpu(vcpu); get_set_sigalrm_vcpu(vcpu);
vm_init_descriptor_tables(vm);
vcpu_init_descriptor_tables(vcpu);
vm_install_exception_handler(vm, UD_VECTOR, guest_ud_handler); vm_install_exception_handler(vm, UD_VECTOR, guest_ud_handler);
/* /*
......
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
* and check it can be retrieved with KVM_GET_MSR, also test * and check it can be retrieved with KVM_GET_MSR, also test
* the invalid LBR formats are rejected. * the invalid LBR formats are rejected.
*/ */
#define _GNU_SOURCE /* for program_invocation_short_name */
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <linux/bitmap.h> #include <linux/bitmap.h>
...@@ -86,9 +85,6 @@ KVM_ONE_VCPU_TEST(vmx_pmu_caps, guest_wrmsr_perf_capabilities, guest_code) ...@@ -86,9 +85,6 @@ KVM_ONE_VCPU_TEST(vmx_pmu_caps, guest_wrmsr_perf_capabilities, guest_code)
struct ucall uc; struct ucall uc;
int r, i; int r, i;
vm_init_descriptor_tables(vcpu->vm);
vcpu_init_descriptor_tables(vcpu);
vcpu_set_msr(vcpu, MSR_IA32_PERF_CAPABILITIES, host_cap.capabilities); vcpu_set_msr(vcpu, MSR_IA32_PERF_CAPABILITIES, host_cap.capabilities);
vcpu_args_set(vcpu, 1, host_cap.capabilities); vcpu_args_set(vcpu, 1, host_cap.capabilities);
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
* value instead of partially decayed timer value * value instead of partially decayed timer value
* *
*/ */
#define _GNU_SOURCE /* for program_invocation_short_name */
#include <fcntl.h> #include <fcntl.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
......
...@@ -19,8 +19,6 @@ ...@@ -19,8 +19,6 @@
* Migration is a command line option. When used on non-numa machines will * Migration is a command line option. When used on non-numa machines will
* exit with error. Test is still usefull on non-numa for testing IPIs. * exit with error. Test is still usefull on non-numa for testing IPIs.
*/ */
#define _GNU_SOURCE /* for program_invocation_short_name */
#include <getopt.h> #include <getopt.h>
#include <pthread.h> #include <pthread.h>
#include <inttypes.h> #include <inttypes.h>
...@@ -410,8 +408,6 @@ int main(int argc, char *argv[]) ...@@ -410,8 +408,6 @@ int main(int argc, char *argv[])
vm = vm_create_with_one_vcpu(&params[0].vcpu, halter_guest_code); vm = vm_create_with_one_vcpu(&params[0].vcpu, halter_guest_code);
vm_init_descriptor_tables(vm);
vcpu_init_descriptor_tables(params[0].vcpu);
vm_install_exception_handler(vm, IPI_VECTOR, guest_ipi_handler); vm_install_exception_handler(vm, IPI_VECTOR, guest_ipi_handler);
virt_pg_map(vm, APIC_DEFAULT_GPA, APIC_DEFAULT_GPA); virt_pg_map(vm, APIC_DEFAULT_GPA, APIC_DEFAULT_GPA);
......
// SPDX-License-Identifier: GPL-2.0-only // SPDX-License-Identifier: GPL-2.0-only
#define _GNU_SOURCE /* for program_invocation_short_name */
#include <fcntl.h> #include <fcntl.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
......
...@@ -109,9 +109,6 @@ int main(int argc, char *argv[]) ...@@ -109,9 +109,6 @@ int main(int argc, char *argv[])
vm = vm_create_with_one_vcpu(&vcpu, guest_code); vm = vm_create_with_one_vcpu(&vcpu, guest_code);
run = vcpu->run; run = vcpu->run;
vm_init_descriptor_tables(vm);
vcpu_init_descriptor_tables(vcpu);
while (1) { while (1) {
vcpu_run(vcpu); vcpu_run(vcpu);
......
...@@ -171,8 +171,9 @@ static volatile bool guest_saw_irq; ...@@ -171,8 +171,9 @@ static volatile bool guest_saw_irq;
static void evtchn_handler(struct ex_regs *regs) static void evtchn_handler(struct ex_regs *regs)
{ {
struct vcpu_info *vi = (void *)VCPU_INFO_VADDR; struct vcpu_info *vi = (void *)VCPU_INFO_VADDR;
vi->evtchn_upcall_pending = 0;
vi->evtchn_pending_sel = 0; vcpu_arch_put_guest(vi->evtchn_upcall_pending, 0);
vcpu_arch_put_guest(vi->evtchn_pending_sel, 0);
guest_saw_irq = true; guest_saw_irq = true;
GUEST_SYNC(TEST_GUEST_SAW_IRQ); GUEST_SYNC(TEST_GUEST_SAW_IRQ);
...@@ -536,8 +537,6 @@ int main(int argc, char *argv[]) ...@@ -536,8 +537,6 @@ int main(int argc, char *argv[])
}; };
vm_ioctl(vm, KVM_XEN_HVM_SET_ATTR, &vec); vm_ioctl(vm, KVM_XEN_HVM_SET_ATTR, &vec);
vm_init_descriptor_tables(vm);
vcpu_init_descriptor_tables(vcpu);
vm_install_exception_handler(vm, EVTCHN_VECTOR, evtchn_handler); vm_install_exception_handler(vm, EVTCHN_VECTOR, evtchn_handler);
if (do_runstate_tests) { if (do_runstate_tests) {
......
...@@ -4,8 +4,6 @@ ...@@ -4,8 +4,6 @@
* *
* Tests for the IA32_XSS MSR. * Tests for the IA32_XSS MSR.
*/ */
#define _GNU_SOURCE /* for program_invocation_short_name */
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include "test_util.h" #include "test_util.h"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment