KVM: selftest: Define _GNU_SOURCE for all selftests code
Sean Christopherson
reviewerPATCH 1/1 KVM: selftest: Define _GNU_SOURCE for all selftests code
Define _GNU_SOURCE is the base CFLAGS instead of relying on selftests to manually #define _GNU_SOURCE, which is repetitive and error prone. E.g. kselftest_harness.h requires _GNU_SOURCE for asprintf(), but if a selftest includes kvm_test_harness.h after stdio.h, the include guards result in the effective version of stdio.h consumed by kvm_test_harness.h not defining asprintf():
In file included from x86_64/fix_hypercall_test.c:12:
In file included from include/kvm_test_harness.h:11:
../kselftest_harness.h:1169:2: error: call to undeclared function
'asprintf'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
1169 | asprintf(&test_name, "%s%s%s.%s", f->name,
| ^When including the rseq selftest's "library" code, #undef _GNU_SOURCE so that rseq.c controls whether or not it wants to build with _GNU_SOURCE.
--- tools/testing/selftests/kvm/Makefile | 4 ++-- tools/testing/selftests/kvm/aarch64/arch_timer.c | 2 -- .../testing/selftests/kvm/aarch64/page_fault_test.c | 1 - tools/testing/selftests/kvm/aarch64/psci_test.c | 3 --- tools/testing/selftests/kvm/aarch64/vgic_init.c | 1 - tools/testing/selftests/kvm/arch_timer.c | 3 --- tools/testing/selftests/kvm/demand_paging_test.c | 3 --- tools/testing/selftests/kvm/dirty_log_test.c | 3 --- tools/testing/selftests/kvm/guest_memfd_test.c | 2 -- tools/testing/selftests/kvm/hardware_disable_test.c | 3 --- tools/testing/selftests/kvm/include/kvm_util_base.h | 12 ++++++------ .../testing/selftests/kvm/include/userfaultfd_util.h | 3 --- tools/testing/selftests/kvm/kvm_binary_stats_test.c | 2 -- tools/testing/selftests/kvm/kvm_create_max_vcpus.c | 2 -- tools/testing/selftests/kvm/kvm_page_table_test.c | 3 --- tools/testing/selftests/kvm/lib/assert.c | 3 --- tools/testing/selftests/kvm/lib/kvm_util.c | 2 -- tools/testing/selftests/kvm/lib/memstress.c | 2 -- tools/testing/selftests/kvm/lib/test_util.c | 2 -- tools/testing/selftests/kvm/lib/userfaultfd_util.c | 3 --- tools/testing/selftests/kvm/lib/x86_64/sev.c | 1 - tools/testing/selftests/kvm/max_guest_memory_test.c | 2 -- .../selftests/kvm/memslot_modification_stress_test.c | 3 --- tools/testing/selftests/kvm/riscv/arch_timer.c | 3 --- tools/testing/selftests/kvm/rseq_test.c | 12 +++++++++--- tools/testing/selftests/kvm/s390x/cmma_test.c | 2 -- tools/testing/selftests/kvm/s390x/sync_regs_test.c | 2 -- tools/testing/selftests/kvm/set_memory_region_test.c | 1 - tools/testing/selftests/kvm/steal_time.c | 1 - tools/testing/selftests/kvm/x86_64/amx_test.c | 2 -- .../kvm/x86_64/exit_on_emulation_failure_test.c | 3 --- tools/testing/selftests/kvm/x86_64/hwcr_msr_test.c | 2 -- tools/testing/selftests/kvm/x86_64/hyperv_cpuid.c | 2 -- tools/testing/selftests/kvm/x86_64/hyperv_evmcs.c | 1 - tools/testing/selftests/kvm/x86_64/hyperv_ipi.c | 2 -- tools/testing/selftests/kvm/x86_64/hyperv_svm_test.c | 1 - .../testing/selftests/kvm/x86_64/hyperv_tlb_flush.c | 2 -- .../selftests/kvm/x86_64/nested_exceptions_test.c | 2 -- .../selftests/kvm/x86_64/nx_huge_pages_test.c | 3 --- .../selftests/kvm/x86_64/platform_info_test.c | 2 -- .../testing/selftests/kvm/x86_64/pmu_counters_test.c | 2 -- .../selftests/kvm/x86_64/pmu_event_filter_test.c | 3 --- .../kvm/x86_64/private_mem_conversions_test.c | 1 - tools/testing/selftests/kvm/x86_64/set_boot_cpu_id.c | 1 - tools/testing/selftests/kvm/x86_64/set_sregs_test.c | 1 - .../kvm/x86_64/smaller_maxphyaddr_emulation_test.c | 3 --- tools/testing/selftests/kvm/x86_64/smm_test.c | 1 - tools/testing/selftests/kvm/x86_64/state_test.c | 1 - tools/testing/selftests/kvm/x86_64/sync_regs_test.c | 2 -- .../selftests/kvm/x86_64/ucna_injection_test.c | 2 -- .../selftests/kvm/x86_64/userspace_msr_exit_test.c | 2 -- .../selftests/kvm/x86_64/vmx_dirty_log_test.c | 3 --- .../testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c | 1 - .../selftests/kvm/x86_64/vmx_preemption_timer_test.c | 1 - tools/testing/selftests/kvm/x86_64/xapic_ipi_test.c | 2 -- .../testing/selftests/kvm/x86_64/xapic_state_test.c | 1 - tools/testing/selftests/kvm/x86_64/xss_msr_test.c | 2 -- 57 files changed, 17 insertions(+), 120 deletions(-)
tools/testing/selftests/kvm/Makefile +2 -2
@@ -226,8 +226,8 @@ LINUX_TOOL_ARCH_INCLUDE = $(top_srcdir)/tools/arch/$(ARCH)/include endif CFLAGS += -Wall -Wstrict-prototypes -Wuninitialized -O2 -g -std=gnu99 \ -Wno-gnu-variable-sized-type-not-at-end -MD -MP -DCONFIG_64BIT \ - -fno-builtin-memcmp -fno-builtin-memcpy -fno-builtin-memset \ - -fno-builtin-strnlen \ + -D_GNU_SOURCE -fno-builtin-memcmp -fno-builtin-memcpy \ + -fno-builtin-memset -fno-builtin-strnlen \ -fno-stack-protector -fno-PIE -I$(LINUX_TOOL_INCLUDE) \ -I$(LINUX_TOOL_ARCH_INCLUDE) -I$(LINUX_HDR_PATH) -Iinclude \ -I$(<D) -Iinclude/$(ARCH_DIR) -I ../rseq -I.. $(EXTRA_CFLAGS) \
tools/testing/selftests/kvm/aarch64/arch_timer.c +0 -2
@@ -5,8 +5,6 @@* * Copyright (c) 2021, Google LLC. */ -#define _GNU_SOURCE -#include "arch_timer.h" #include "delay.h" #include "gic.h"
tools/testing/selftests/kvm/aarch64/page_fault_test.c +0 -1
@@ -7,7 +7,6 @@* 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). */ -#define _GNU_SOURCE#include <linux/bitmap.h> #include <fcntl.h> #include <test_util.h>
tools/testing/selftests/kvm/aarch64/psci_test.c +0 -3
@@ -10,9 +10,6 @@* - A test for KVM's handling of PSCI SYSTEM_SUSPEND and the associated * KVM_SYSTEM_EVENT_SUSPEND UAPI. */ - -#define _GNU_SOURCE -#include <linux/psci.h> #include "kvm_util.h"
tools/testing/selftests/kvm/aarch64/vgic_init.c +0 -1
@@ -4,7 +4,6 @@* * Copyright (C) 2020, Red Hat, Inc. */ -#define _GNU_SOURCE#include <linux/kernel.h> #include <sys/syscall.h> #include <asm/kvm.h>
tools/testing/selftests/kvm/arch_timer.c +0 -3
@@ -19,9 +19,6 @@* * Copyright (c) 2021, Google LLC. */ - -#define _GNU_SOURCE -#include <stdlib.h> #include <pthread.h> #include <linux/sizes.h>
tools/testing/selftests/kvm/demand_paging_test.c +0 -3
@@ -6,9 +6,6 @@* Copyright (C) 2018, Red Hat, Inc. * Copyright (C) 2019, Google, Inc. */ - -#define _GNU_SOURCE/* for pipe2 */ -#include <inttypes.h> #include <stdio.h> #include <stdlib.h>
tools/testing/selftests/kvm/dirty_log_test.c +0 -3
@@ -4,9 +4,6 @@* * Copyright (C) 2018, Red Hat, Inc. */ - -#define _GNU_SOURCE/* for program_invocation_name */ -#include <stdio.h> #include <stdlib.h> #include <pthread.h>
tools/testing/selftests/kvm/guest_memfd_test.c +0 -2
@@ -4,8 +4,6 @@* * Author: Chao Peng <[email protected]> */ - -#define _GNU_SOURCE#include <stdlib.h> #include <string.h> #include <unistd.h>
tools/testing/selftests/kvm/hardware_disable_test.c +0 -3
@@ -4,9 +4,6 @@* kvm_arch_hardware_disable is called and it attempts to unregister the user * return notifiers. */ - -#define _GNU_SOURCE -#include <fcntl.h> #include <pthread.h> #include <semaphore.h>
tools/testing/selftests/kvm/include/kvm_util_base.h +6 -6
@@ -27,12 +27,12 @@/* * 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) -* #undefs and #defines static_assert() as a direct alias to _Static_assert(), -* i.e. effectively makes the message mandatory. Many KVM selftests #define -* _GNU_SOURCE for various reasons, and _GNU_SOURCE implies _ISOC11_SOURCE. As -* a result, static_assert() behavior is non-deterministic and may or may not -* require a message depending on #include order. +* 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)
tools/testing/selftests/kvm/include/userfaultfd_util.h +0 -3
@@ -5,9 +5,6 @@* Copyright (C) 2018, Red Hat, Inc. * Copyright (C) 2019-2022 Google LLC */ - -#define _GNU_SOURCE/* for pipe2 */ -#include <inttypes.h> #include <time.h> #include <pthread.h>
tools/testing/selftests/kvm/kvm_binary_stats_test.c +0 -2
@@ -6,8 +6,6 @@* * Test the fd-based interface for KVM statistics. */ - -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <fcntl.h> #include <stdio.h> #include <stdlib.h>
tools/testing/selftests/kvm/kvm_create_max_vcpus.c +0 -2
@@ -6,8 +6,6 @@* * Test for KVM_CAP_MAX_VCPUS and KVM_CAP_MAX_VCPU_ID. */ - -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <fcntl.h> #include <stdio.h> #include <stdlib.h>
tools/testing/selftests/kvm/kvm_page_table_test.c +0 -3
@@ -8,9 +8,6 @@* page size have been pre-allocated on your system, if you are planning to * use hugepages to back the guest memory for testing. */ - -#define _GNU_SOURCE/* for program_invocation_name */ -#include <stdio.h> #include <stdlib.h> #include <time.h>
tools/testing/selftests/kvm/lib/assert.c +0 -3
@@ -4,9 +4,6 @@* * Copyright (C) 2018, Google LLC. */ - -#define _GNU_SOURCE/* for getline(3) and strchrnul(3)*/ -#include "test_util.h" #include <execinfo.h>
tools/testing/selftests/kvm/lib/kvm_util.c +0 -2
@@ -4,8 +4,6 @@* * Copyright (C) 2018, Google LLC. */ - -#define _GNU_SOURCE/* for program_invocation_name */ #include "test_util.h" #include "kvm_util.h" #include "processor.h"
tools/testing/selftests/kvm/lib/memstress.c +0 -2
@@ -2,8 +2,6 @@/* * Copyright (C) 2020, Google LLC. */ -#define _GNU_SOURCE -#include <inttypes.h> #include <linux/bitmap.h>
tools/testing/selftests/kvm/lib/test_util.c +0 -2
@@ -4,8 +4,6 @@* * Copyright (C) 2020, Google LLC. */ - -#define _GNU_SOURCE#include <stdio.h> #include <stdarg.h> #include <assert.h>
tools/testing/selftests/kvm/lib/userfaultfd_util.c +0 -3
@@ -6,9 +6,6 @@* Copyright (C) 2018, Red Hat, Inc. * Copyright (C) 2019-2022 Google LLC */ - -#define _GNU_SOURCE/* for pipe2 */ -#include <inttypes.h> #include <stdio.h> #include <stdlib.h>
tools/testing/selftests/kvm/lib/x86_64/sev.c +0 -1
@@ -1,5 +1,4 @@// SPDX-License-Identifier: GPL-2.0-only -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <stdint.h> #include <stdbool.h>
tools/testing/selftests/kvm/max_guest_memory_test.c +0 -2
@@ -1,6 +1,4 @@// SPDX-License-Identifier: GPL-2.0 -#define _GNU_SOURCE -#include <stdio.h> #include <stdlib.h> #include <pthread.h>
tools/testing/selftests/kvm/memslot_modification_stress_test.c +0 -3
@@ -6,9 +6,6 @@* Copyright (C) 2018, Red Hat, Inc. * Copyright (C) 2020, Google, Inc. */ - -#define _GNU_SOURCE/* for program_invocation_name */ -#include <stdio.h> #include <stdlib.h> #include <sys/syscall.h>
tools/testing/selftests/kvm/riscv/arch_timer.c +0 -3
@@ -7,9 +7,6 @@* * Copyright (c) 2024, Intel Corporation. */ - -#define _GNU_SOURCE -#include "arch_timer.h" #include "kvm_util.h" #include "processor.h"
tools/testing/selftests/kvm/rseq_test.c +9 -3
@@ -1,5 +1,13 @@// 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 <fcntl.h> #include <pthread.h>
@@ -20,8 +28,6 @@#include "processor.h" #include "test_util.h" -#include "../rseq/rseq.c" -/* * Any bug related to task migration is likely to be timing-dependent; perform * a large number of migrations to reduce the odds of a false negative.
tools/testing/selftests/kvm/s390x/cmma_test.c +0 -2
@@ -7,8 +7,6 @@* Authors: * Nico Boehr <[email protected]> */ - -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <fcntl.h> #include <stdio.h> #include <stdlib.h>
tools/testing/selftests/kvm/s390x/sync_regs_test.c +0 -2
@@ -10,8 +10,6 @@* * Test expected behavior of the KVM_CAP_SYNC_REGS functionality. */ - -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <fcntl.h> #include <stdio.h> #include <stdlib.h>
tools/testing/selftests/kvm/set_memory_region_test.c +0 -1
@@ -1,5 +1,4 @@// SPDX-License-Identifier: GPL-2.0 -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <fcntl.h> #include <pthread.h> #include <sched.h>
tools/testing/selftests/kvm/steal_time.c +0 -1
@@ -4,7 +4,6 @@* * Copyright (C) 2020, Red Hat, Inc. */ -#define _GNU_SOURCE#include <stdio.h> #include <time.h> #include <sched.h>
tools/testing/selftests/kvm/x86_64/amx_test.c +0 -2
@@ -6,8 +6,6 @@* * Tests for amx #NM exception and save/restore. */ - -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <fcntl.h> #include <stdio.h> #include <stdlib.h>
tools/testing/selftests/kvm/x86_64/exit_on_emulation_failure_test.c +0 -3
@@ -4,9 +4,6 @@* * Test for KVM_CAP_EXIT_ON_EMULATION_FAILURE. */ - -#define _GNU_SOURCE/* for program_invocation_short_name */ -#include "flds_emulation.h" #include "test_util.h"
tools/testing/selftests/kvm/x86_64/hwcr_msr_test.c +0 -2
@@ -2,8 +2,6 @@/* * Copyright (C) 2023, Google LLC. */ - -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <sys/ioctl.h> #include "test_util.h"
tools/testing/selftests/kvm/x86_64/hyperv_cpuid.c +0 -2
@@ -7,8 +7,6 @@* 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 <stdio.h> #include <stdlib.h>
tools/testing/selftests/kvm/x86_64/hyperv_evmcs.c +0 -1
@@ -4,7 +4,6 @@* * Tests for Enlightened VMCS, including nested guest state. */ -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <fcntl.h> #include <stdio.h> #include <stdlib.h>
tools/testing/selftests/kvm/x86_64/hyperv_ipi.c +0 -2
@@ -5,8 +5,6 @@* Copyright (C) 2022, Red Hat, Inc. * */ - -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <pthread.h> #include <inttypes.h>
tools/testing/selftests/kvm/x86_64/hyperv_svm_test.c +0 -1
@@ -4,7 +4,6 @@* * Tests for Hyper-V extensions to SVM. */ -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <fcntl.h> #include <stdio.h> #include <stdlib.h>
tools/testing/selftests/kvm/x86_64/hyperv_tlb_flush.c +0 -2
@@ -5,8 +5,6 @@* Copyright (C) 2022, Red Hat, Inc. * */ - -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <asm/barrier.h> #include <pthread.h> #include <inttypes.h>
tools/testing/selftests/kvm/x86_64/nested_exceptions_test.c +0 -2
@@ -1,6 +1,4 @@// SPDX-License-Identifier: GPL-2.0-only -#define _GNU_SOURCE/* for program_invocation_short_name */ -#include "test_util.h" #include "kvm_util.h" #include "processor.h"
tools/testing/selftests/kvm/x86_64/nx_huge_pages_test.c +0 -3
@@ -5,9 +5,6 @@* * Copyright (C) 2022, Google LLC. */ - -#define _GNU_SOURCE -#include <fcntl.h> #include <stdint.h> #include <time.h>
tools/testing/selftests/kvm/x86_64/platform_info_test.c +0 -2
@@ -9,8 +9,6 @@* Verifies expected behavior of controlling guest access to * MSR_PLATFORM_INFO. */ - -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <fcntl.h> #include <stdio.h> #include <stdlib.h>
tools/testing/selftests/kvm/x86_64/pmu_counters_test.c +0 -2
@@ -2,8 +2,6 @@/* * Copyright (C) 2023, Tencent, Inc. */ - -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <x86intrin.h> #include "pmu.h"
tools/testing/selftests/kvm/x86_64/pmu_event_filter_test.c +0 -3
@@ -9,9 +9,6 @@* Verifies the expected behavior of allow lists and deny lists for * virtual PMU events. */ - -#define _GNU_SOURCE/* for program_invocation_short_name */ -#include "kvm_util.h" #include "pmu.h" #include "processor.h"
tools/testing/selftests/kvm/x86_64/private_mem_conversions_test.c +0 -1
@@ -2,7 +2,6 @@/* * Copyright (C) 2022, Google LLC. */ -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <fcntl.h> #include <limits.h> #include <pthread.h>
tools/testing/selftests/kvm/x86_64/set_boot_cpu_id.c +0 -1
@@ -4,7 +4,6 @@* * Copyright (C) 2020, Red Hat, Inc. */ -#define _GNU_SOURCE/* for program_invocation_name */ #include <fcntl.h> #include <stdio.h> #include <stdlib.h>
tools/testing/selftests/kvm/x86_64/set_sregs_test.c +0 -1
@@ -10,7 +10,6 @@* 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. */ -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <fcntl.h> #include <stdio.h> #include <stdlib.h>
tools/testing/selftests/kvm/x86_64/smaller_maxphyaddr_emulation_test.c +0 -3
@@ -5,9 +5,6 @@* Test that KVM emulates instructions in response to EPT violations when * allow_smaller_maxphyaddr is enabled and guest.MAXPHYADDR < host.MAXPHYADDR. */ - -#define _GNU_SOURCE/* for program_invocation_short_name */ -#include "flds_emulation.h" #include "test_util.h"
tools/testing/selftests/kvm/x86_64/smm_test.c +0 -1
@@ -4,7 +4,6 @@* * Tests for SMM. */ -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <fcntl.h> #include <stdio.h> #include <stdlib.h>
tools/testing/selftests/kvm/x86_64/state_test.c +0 -1
@@ -6,7 +6,6 @@* * Tests for vCPU state save/restore, including nested guest state. */ -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <fcntl.h> #include <stdio.h> #include <stdlib.h>
tools/testing/selftests/kvm/x86_64/sync_regs_test.c +0 -2
@@ -8,8 +8,6 @@* 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. */ - -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <fcntl.h> #include <stdio.h> #include <stdlib.h>
tools/testing/selftests/kvm/x86_64/ucna_injection_test.c +0 -2
@@ -17,8 +17,6 @@* delivered into the guest or not. * */ - -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <pthread.h> #include <inttypes.h> #include <string.h>
tools/testing/selftests/kvm/x86_64/userspace_msr_exit_test.c +0 -2
@@ -4,8 +4,6 @@* * Tests for exiting into userspace on registered MSRs */ - -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <sys/ioctl.h> #include "kvm_test_harness.h"
tools/testing/selftests/kvm/x86_64/vmx_dirty_log_test.c +0 -3
@@ -4,9 +4,6 @@* * Copyright (C) 2018, Red Hat, Inc. */ - -#define _GNU_SOURCE/* for program_invocation_name */ -#include <stdio.h> #include <stdlib.h> #include <linux/bitmap.h>
tools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c +0 -1
@@ -10,7 +10,6 @@* and check it can be retrieved with KVM_GET_MSR, also test * the invalid LBR formats are rejected. */ -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <sys/ioctl.h> #include <linux/bitmap.h>
tools/testing/selftests/kvm/x86_64/vmx_preemption_timer_test.c +0 -1
@@ -9,7 +9,6 @@* value instead of partially decayed timer value * */ -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <fcntl.h> #include <stdio.h> #include <stdlib.h>
tools/testing/selftests/kvm/x86_64/xapic_ipi_test.c +0 -2
@@ -19,8 +19,6 @@* 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. */ - -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <getopt.h> #include <pthread.h> #include <inttypes.h>
tools/testing/selftests/kvm/x86_64/xapic_state_test.c +0 -1
@@ -1,5 +1,4 @@// SPDX-License-Identifier: GPL-2.0-only -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <fcntl.h> #include <stdio.h> #include <stdlib.h>
tools/testing/selftests/kvm/x86_64/xss_msr_test.c +0 -2
@@ -4,8 +4,6 @@* * Tests for the IA32_XSS MSR. */ - -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <sys/ioctl.h> #include "test_util.h"
base-commit: 7b076c6a308ec5bce9fc96e2935443ed228b9148
Signature · 1 line
2.44.0.769.g3c40516874-goog
Quoted 12 lines · Sean Christopherson
Define
_GNU_SOURCEis the base CFLAGS instead of relying on selftests to manually #define_GNU_SOURCE, which is repetitive and error prone. E.g.kselftest_harness.hrequires_GNU_SOURCEforasprintf(), but if a selftest includeskvm_test_harness.hafterstdio.h, the include guards result in the effective version ofstdio.hconsumed bykvm_test_harness.hnot definingasprintf():In file included from
x86_64/fix_hypercall_test.c:12:
In file included frominclude/kvm_test_harness.h:11:
../kselftest_harness.h:1169:2: error: call to undeclared function
'asprintf'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
Quoted 8 lines
1169 | asprintf(&test_name, "%s%s%s.%s", f->name, | ^When including the rseq selftest's "library" code, #undef
_GNU_SOURCEso thatrseq.ccontrols whether or not it wants to build with_GNU_SOURCE.Reported-by Muhammad Usama Anjum <[email protected]>Signed-off-by Sean Christopherson <[email protected]>
Thanks for sending the patch.
Quoted 821 lines
--- tools/testing/selftests/kvm/Makefile | 4 ++-- tools/testing/selftests/kvm/aarch64/arch_timer.c | 2 -- .../testing/selftests/kvm/aarch64/page_fault_test.c | 1 - tools/testing/selftests/kvm/aarch64/psci_test.c | 3 --- tools/testing/selftests/kvm/aarch64/vgic_init.c | 1 - tools/testing/selftests/kvm/arch_timer.c | 3 --- tools/testing/selftests/kvm/demand_paging_test.c | 3 --- tools/testing/selftests/kvm/dirty_log_test.c | 3 --- tools/testing/selftests/kvm/guest_memfd_test.c | 2 -- tools/testing/selftests/kvm/hardware_disable_test.c | 3 --- tools/testing/selftests/kvm/include/kvm_util_base.h | 12 ++++++------ .../testing/selftests/kvm/include/userfaultfd_util.h | 3 --- tools/testing/selftests/kvm/kvm_binary_stats_test.c | 2 -- tools/testing/selftests/kvm/kvm_create_max_vcpus.c | 2 -- tools/testing/selftests/kvm/kvm_page_table_test.c | 3 --- tools/testing/selftests/kvm/lib/assert.c | 3 --- tools/testing/selftests/kvm/lib/kvm_util.c | 2 -- tools/testing/selftests/kvm/lib/memstress.c | 2 -- tools/testing/selftests/kvm/lib/test_util.c | 2 -- tools/testing/selftests/kvm/lib/userfaultfd_util.c | 3 --- tools/testing/selftests/kvm/lib/x86_64/sev.c | 1 - tools/testing/selftests/kvm/max_guest_memory_test.c | 2 -- .../selftests/kvm/memslot_modification_stress_test.c | 3 --- tools/testing/selftests/kvm/riscv/arch_timer.c | 3 --- tools/testing/selftests/kvm/rseq_test.c | 12 +++++++++--- tools/testing/selftests/kvm/s390x/cmma_test.c | 2 -- tools/testing/selftests/kvm/s390x/sync_regs_test.c | 2 -- tools/testing/selftests/kvm/set_memory_region_test.c | 1 - tools/testing/selftests/kvm/steal_time.c | 1 - tools/testing/selftests/kvm/x86_64/amx_test.c | 2 -- .../kvm/x86_64/exit_on_emulation_failure_test.c | 3 --- tools/testing/selftests/kvm/x86_64/hwcr_msr_test.c | 2 -- tools/testing/selftests/kvm/x86_64/hyperv_cpuid.c | 2 -- tools/testing/selftests/kvm/x86_64/hyperv_evmcs.c | 1 - tools/testing/selftests/kvm/x86_64/hyperv_ipi.c | 2 -- tools/testing/selftests/kvm/x86_64/hyperv_svm_test.c | 1 - .../testing/selftests/kvm/x86_64/hyperv_tlb_flush.c | 2 -- .../selftests/kvm/x86_64/nested_exceptions_test.c | 2 -- .../selftests/kvm/x86_64/nx_huge_pages_test.c | 3 --- .../selftests/kvm/x86_64/platform_info_test.c | 2 -- .../testing/selftests/kvm/x86_64/pmu_counters_test.c | 2 -- .../selftests/kvm/x86_64/pmu_event_filter_test.c | 3 --- .../kvm/x86_64/private_mem_conversions_test.c | 1 - tools/testing/selftests/kvm/x86_64/set_boot_cpu_id.c | 1 - tools/testing/selftests/kvm/x86_64/set_sregs_test.c | 1 - .../kvm/x86_64/smaller_maxphyaddr_emulation_test.c | 3 --- tools/testing/selftests/kvm/x86_64/smm_test.c | 1 - tools/testing/selftests/kvm/x86_64/state_test.c | 1 - tools/testing/selftests/kvm/x86_64/sync_regs_test.c | 2 -- .../selftests/kvm/x86_64/ucna_injection_test.c | 2 -- .../selftests/kvm/x86_64/userspace_msr_exit_test.c | 2 -- .../selftests/kvm/x86_64/vmx_dirty_log_test.c | 3 --- .../testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c | 1 - .../selftests/kvm/x86_64/vmx_preemption_timer_test.c | 1 - tools/testing/selftests/kvm/x86_64/xapic_ipi_test.c | 2 -- .../testing/selftests/kvm/x86_64/xapic_state_test.c | 1 - tools/testing/selftests/kvm/x86_64/xss_msr_test.c | 2 -- 57 files changed, 17 insertions(+), 120 deletions(-)tools/testing/selftests/kvm/Makefile +2
-2@@ -226,8 +226,8 @@ LINUX_TOOL_ARCH_INCLUDE = $(top_srcdir)/tools/arch/$(ARCH)/include endif CFLAGS += -Wall -Wstrict-prototypes -Wuninitialized -O2 -g -std=gnu99 \ -Wno-gnu-variable-sized-type-not-at-end -MD -MP -DCONFIG_64BIT \ - -fno-builtin-memcmp -fno-builtin-memcpy -fno-builtin-memset \ - -fno-builtin-strnlen \ + -D_GNU_SOURCE -fno-builtin-memcmp -fno-builtin-memcpy \ + -fno-builtin-memset -fno-builtin-strnlen \ -fno-stack-protector -fno-PIE -I$(LINUX_TOOL_INCLUDE) \ -I$(LINUX_TOOL_ARCH_INCLUDE) -I$(LINUX_HDR_PATH) -Iinclude \ -I$(<D) -Iinclude/$(ARCH_DIR) -I ../rseq -I.. $(EXTRA_CFLAGS) \tools/testing/selftests/kvm/aarch64/arch_timer.c +0
-2@@ -5,8 +5,6 @@* * Copyright (c) 2021, Google LLC. */ -#define _GNU_SOURCE -#include "arch_timer.h" #include "delay.h" #include "gic.h" tools/testing/selftests/kvm/aarch64/page_fault_test.c +0
-1@@ -7,7 +7,6 @@* 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). */ -#define _GNU_SOURCE#include <linux/bitmap.h> #include <fcntl.h> #include <test_util.h> tools/testing/selftests/kvm/aarch64/psci_test.c +0
-3@@ -10,9 +10,6 @@* - A test for KVM's handling of PSCI SYSTEM_SUSPEND and the associated * KVM_SYSTEM_EVENT_SUSPEND UAPI. */ - -#define _GNU_SOURCE -#include <linux/psci.h> #include "kvm_util.h" tools/testing/selftests/kvm/aarch64/vgic_init.c +0
-1@@ -4,7 +4,6 @@* * Copyright (C) 2020, Red Hat, Inc. */ -#define _GNU_SOURCE#include <linux/kernel.h> #include <sys/syscall.h> #include <asm/kvm.h> tools/testing/selftests/kvm/arch_timer.c +0
-3@@ -19,9 +19,6 @@* * Copyright (c) 2021, Google LLC. */ - -#define _GNU_SOURCE -#include <stdlib.h> #include <pthread.h> #include <linux/sizes.h> tools/testing/selftests/kvm/demand_paging_test.c +0
-3@@ -6,9 +6,6 @@* Copyright (C) 2018, Red Hat, Inc. * Copyright (C) 2019, Google, Inc. */ - -#define _GNU_SOURCE/* for pipe2 */ -#include <inttypes.h> #include <stdio.h> #include <stdlib.h> tools/testing/selftests/kvm/dirty_log_test.c +0
-3@@ -4,9 +4,6 @@* * Copyright (C) 2018, Red Hat, Inc. */ - -#define _GNU_SOURCE/* for program_invocation_name */ -#include <stdio.h> #include <stdlib.h> #include <pthread.h> tools/testing/selftests/kvm/guest_memfd_test.c +0
-2@@ -4,8 +4,6 @@* * Author: Chao Peng <[email protected]> */ - -#define _GNU_SOURCE#include <stdlib.h> #include <string.h> #include <unistd.h> tools/testing/selftests/kvm/hardware_disable_test.c +0
-3@@ -4,9 +4,6 @@* kvm_arch_hardware_disable is called and it attempts to unregister the user * return notifiers. */ - -#define _GNU_SOURCE -#include <fcntl.h> #include <pthread.h> #include <semaphore.h> tools/testing/selftests/kvm/include/kvm_util_base.h +6
-6@@ -27,12 +27,12 @@/* * 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) -* #undefs and #defines static_assert() as a direct alias to _Static_assert(), -* i.e. effectively makes the message mandatory. Many KVM selftests #define -* _GNU_SOURCE for various reasons, and _GNU_SOURCE implies _ISOC11_SOURCE. As -* a result, static_assert() behavior is non-deterministic and may or may not -* require a message depending on #include order. +* 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)tools/testing/selftests/kvm/include/userfaultfd_util.h +0
-3@@ -5,9 +5,6 @@* Copyright (C) 2018, Red Hat, Inc. * Copyright (C) 2019-2022 Google LLC */ - -#define _GNU_SOURCE/* for pipe2 */ -#include <inttypes.h> #include <time.h> #include <pthread.h> tools/testing/selftests/kvm/kvm_binary_stats_test.c +0
-2@@ -6,8 +6,6 @@* * Test the fd-based interface for KVM statistics. */ - -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <fcntl.h> #include <stdio.h> #include <stdlib.h> tools/testing/selftests/kvm/kvm_create_max_vcpus.c +0
-2@@ -6,8 +6,6 @@* * Test for KVM_CAP_MAX_VCPUS and KVM_CAP_MAX_VCPU_ID. */ - -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <fcntl.h> #include <stdio.h> #include <stdlib.h> tools/testing/selftests/kvm/kvm_page_table_test.c +0
-3@@ -8,9 +8,6 @@* page size have been pre-allocated on your system, if you are planning to * use hugepages to back the guest memory for testing. */ - -#define _GNU_SOURCE/* for program_invocation_name */ -#include <stdio.h> #include <stdlib.h> #include <time.h> tools/testing/selftests/kvm/lib/assert.c +0
-3@@ -4,9 +4,6 @@* * Copyright (C) 2018, Google LLC. */ - -#define _GNU_SOURCE/* for getline(3) and strchrnul(3)*/ -#include "test_util.h" #include <execinfo.h> tools/testing/selftests/kvm/lib/kvm_util.c +0
-2@@ -4,8 +4,6 @@* * Copyright (C) 2018, Google LLC. */ - -#define _GNU_SOURCE/* for program_invocation_name */ #include "test_util.h" #include "kvm_util.h" #include "processor.h" tools/testing/selftests/kvm/lib/memstress.c +0
-2@@ -2,8 +2,6 @@/* * Copyright (C) 2020, Google LLC. */ -#define _GNU_SOURCE -#include <inttypes.h> #include <linux/bitmap.h> tools/testing/selftests/kvm/lib/test_util.c +0
-2@@ -4,8 +4,6 @@* * Copyright (C) 2020, Google LLC. */ - -#define _GNU_SOURCE#include <stdio.h> #include <stdarg.h> #include <assert.h> tools/testing/selftests/kvm/lib/userfaultfd_util.c +0
-3@@ -6,9 +6,6 @@* Copyright (C) 2018, Red Hat, Inc. * Copyright (C) 2019-2022 Google LLC */ - -#define _GNU_SOURCE/* for pipe2 */ -#include <inttypes.h> #include <stdio.h> #include <stdlib.h> tools/testing/selftests/kvm/lib/x86_64/sev.c +0
-1@@ -1,5 +1,4 @@// SPDX-License-Identifier: GPL-2.0-only -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <stdint.h> #include <stdbool.h> tools/testing/selftests/kvm/max_guest_memory_test.c +0
-2@@ -1,6 +1,4 @@// SPDX-License-Identifier: GPL-2.0 -#define _GNU_SOURCE -#include <stdio.h> #include <stdlib.h> #include <pthread.h> tools/testing/selftests/kvm/memslot_modification_stress_test.c +0
-3@@ -6,9 +6,6 @@* Copyright (C) 2018, Red Hat, Inc. * Copyright (C) 2020, Google, Inc. */ - -#define _GNU_SOURCE/* for program_invocation_name */ -#include <stdio.h> #include <stdlib.h> #include <sys/syscall.h> tools/testing/selftests/kvm/riscv/arch_timer.c +0
-3@@ -7,9 +7,6 @@* * Copyright (c) 2024, Intel Corporation. */ - -#define _GNU_SOURCE -#include "arch_timer.h" #include "kvm_util.h" #include "processor.h" tools/testing/selftests/kvm/rseq_test.c +9
-3@@ -1,5 +1,13 @@// 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 <fcntl.h> #include <pthread.h> @@ -20,8 +28,6 @@#include "processor.h" #include "test_util.h" -#include "../rseq/rseq.c" -/* * Any bug related to task migration is likely to be timing-dependent; perform * a large number of migrations to reduce the odds of a false negative. tools/testing/selftests/kvm/s390x/cmma_test.c +0
-2@@ -7,8 +7,6 @@* Authors: * Nico Boehr <[email protected]> */ - -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <fcntl.h> #include <stdio.h> #include <stdlib.h> tools/testing/selftests/kvm/s390x/sync_regs_test.c +0
-2@@ -10,8 +10,6 @@* * Test expected behavior of the KVM_CAP_SYNC_REGS functionality. */ - -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <fcntl.h> #include <stdio.h> #include <stdlib.h> tools/testing/selftests/kvm/set_memory_region_test.c +0
-1@@ -1,5 +1,4 @@// SPDX-License-Identifier: GPL-2.0 -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <fcntl.h> #include <pthread.h> #include <sched.h> tools/testing/selftests/kvm/steal_time.c +0
-1@@ -4,7 +4,6 @@* * Copyright (C) 2020, Red Hat, Inc. */ -#define _GNU_SOURCE#include <stdio.h> #include <time.h> #include <sched.h> tools/testing/selftests/kvm/x86_64/amx_test.c +0
-2@@ -6,8 +6,6 @@* * Tests for amx #NM exception and save/restore. */ - -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <fcntl.h> #include <stdio.h> #include <stdlib.h> tools/testing/selftests/kvm/x86_64/exit_on_emulation_failure_test.c +0
-3@@ -4,9 +4,6 @@* * Test for KVM_CAP_EXIT_ON_EMULATION_FAILURE. */ - -#define _GNU_SOURCE/* for program_invocation_short_name */ -#include "flds_emulation.h" #include "test_util.h" tools/testing/selftests/kvm/x86_64/hwcr_msr_test.c +0
-2@@ -2,8 +2,6 @@/* * Copyright (C) 2023, Google LLC. */ - -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <sys/ioctl.h> #include "test_util.h" tools/testing/selftests/kvm/x86_64/hyperv_cpuid.c +0
-2@@ -7,8 +7,6 @@* 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 <stdio.h> #include <stdlib.h> tools/testing/selftests/kvm/x86_64/hyperv_evmcs.c +0
-1@@ -4,7 +4,6 @@* * Tests for Enlightened VMCS, including nested guest state. */ -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <fcntl.h> #include <stdio.h> #include <stdlib.h> tools/testing/selftests/kvm/x86_64/hyperv_ipi.c +0
-2@@ -5,8 +5,6 @@* Copyright (C) 2022, Red Hat, Inc. * */ - -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <pthread.h> #include <inttypes.h> tools/testing/selftests/kvm/x86_64/hyperv_svm_test.c +0
-1@@ -4,7 +4,6 @@* * Tests for Hyper-V extensions to SVM. */ -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <fcntl.h> #include <stdio.h> #include <stdlib.h> tools/testing/selftests/kvm/x86_64/hyperv_tlb_flush.c +0
-2@@ -5,8 +5,6 @@* Copyright (C) 2022, Red Hat, Inc. * */ - -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <asm/barrier.h> #include <pthread.h> #include <inttypes.h> tools/testing/selftests/kvm/x86_64/nested_exceptions_test.c +0
-2@@ -1,6 +1,4 @@// SPDX-License-Identifier: GPL-2.0-only -#define _GNU_SOURCE/* for program_invocation_short_name */ -#include "test_util.h" #include "kvm_util.h" #include "processor.h" tools/testing/selftests/kvm/x86_64/nx_huge_pages_test.c +0
-3@@ -5,9 +5,6 @@* * Copyright (C) 2022, Google LLC. */ - -#define _GNU_SOURCE -#include <fcntl.h> #include <stdint.h> #include <time.h> tools/testing/selftests/kvm/x86_64/platform_info_test.c +0
-2@@ -9,8 +9,6 @@* Verifies expected behavior of controlling guest access to * MSR_PLATFORM_INFO. */ - -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <fcntl.h> #include <stdio.h> #include <stdlib.h> tools/testing/selftests/kvm/x86_64/pmu_counters_test.c +0
-2@@ -2,8 +2,6 @@/* * Copyright (C) 2023, Tencent, Inc. */ - -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <x86intrin.h> #include "pmu.h" tools/testing/selftests/kvm/x86_64/pmu_event_filter_test.c +0
-3@@ -9,9 +9,6 @@* Verifies the expected behavior of allow lists and deny lists for * virtual PMU events. */ - -#define _GNU_SOURCE/* for program_invocation_short_name */ -#include "kvm_util.h" #include "pmu.h" #include "processor.h" tools/testing/selftests/kvm/x86_64/private_mem_conversions_test.c +0
-1@@ -2,7 +2,6 @@/* * Copyright (C) 2022, Google LLC. */ -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <fcntl.h> #include <limits.h> #include <pthread.h> tools/testing/selftests/kvm/x86_64/set_boot_cpu_id.c +0
-1@@ -4,7 +4,6 @@* * Copyright (C) 2020, Red Hat, Inc. */ -#define _GNU_SOURCE/* for program_invocation_name */ #include <fcntl.h> #include <stdio.h> #include <stdlib.h> tools/testing/selftests/kvm/x86_64/set_sregs_test.c +0
-1@@ -10,7 +10,6 @@* 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. */ -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <fcntl.h> #include <stdio.h> #include <stdlib.h> tools/testing/selftests/kvm/x86_64/smaller_maxphyaddr_emulation_test.c +0
-3@@ -5,9 +5,6 @@* Test that KVM emulates instructions in response to EPT violations when * allow_smaller_maxphyaddr is enabled and guest.MAXPHYADDR < host.MAXPHYADDR. */ - -#define _GNU_SOURCE/* for program_invocation_short_name */ -#include "flds_emulation.h" #include "test_util.h" tools/testing/selftests/kvm/x86_64/smm_test.c +0
-1@@ -4,7 +4,6 @@* * Tests for SMM. */ -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <fcntl.h> #include <stdio.h> #include <stdlib.h> tools/testing/selftests/kvm/x86_64/state_test.c +0
-1@@ -6,7 +6,6 @@* * Tests for vCPU state save/restore, including nested guest state. */ -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <fcntl.h> #include <stdio.h> #include <stdlib.h> tools/testing/selftests/kvm/x86_64/sync_regs_test.c +0
-2@@ -8,8 +8,6 @@* 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. */ - -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <fcntl.h> #include <stdio.h> #include <stdlib.h> tools/testing/selftests/kvm/x86_64/ucna_injection_test.c +0
-2@@ -17,8 +17,6 @@* delivered into the guest or not. * */ - -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <pthread.h> #include <inttypes.h> #include <string.h> tools/testing/selftests/kvm/x86_64/userspace_msr_exit_test.c +0
-2@@ -4,8 +4,6 @@* * Tests for exiting into userspace on registered MSRs */ - -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <sys/ioctl.h> #include "kvm_test_harness.h" tools/testing/selftests/kvm/x86_64/vmx_dirty_log_test.c +0
-3@@ -4,9 +4,6 @@* * Copyright (C) 2018, Red Hat, Inc. */ - -#define _GNU_SOURCE/* for program_invocation_name */ -#include <stdio.h> #include <stdlib.h> #include <linux/bitmap.h> tools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c +0
-1@@ -10,7 +10,6 @@* and check it can be retrieved with KVM_GET_MSR, also test * the invalid LBR formats are rejected. */ -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <sys/ioctl.h> #include <linux/bitmap.h> tools/testing/selftests/kvm/x86_64/vmx_preemption_timer_test.c +0
-1@@ -9,7 +9,6 @@* value instead of partially decayed timer value * */ -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <fcntl.h> #include <stdio.h> #include <stdlib.h> tools/testing/selftests/kvm/x86_64/xapic_ipi_test.c +0
-2@@ -19,8 +19,6 @@* 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. */ - -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <getopt.h> #include <pthread.h> #include <inttypes.h> tools/testing/selftests/kvm/x86_64/xapic_state_test.c +0
-1@@ -1,5 +1,4 @@// SPDX-License-Identifier: GPL-2.0-only -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <fcntl.h> #include <stdio.h> #include <stdlib.h> tools/testing/selftests/kvm/x86_64/xss_msr_test.c +0
-2@@ -4,8 +4,6 @@* * Tests for the IA32_XSS MSR. */ - -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <sys/ioctl.h> #include "test_util.h" base-commit:
7b076c6a308ec5bce9fc96e2935443ed228b9148
Signature · 2 lines
BR, Muhammad Usama Anjum
Quoted 13 lines · On Wed, Apr 24, 2024 at 12:33?AM Sean Christopherson <[email protected]> wrote:
Define
_GNU_SOURCEis the base CFLAGS instead of relying on selftests to manually #define_GNU_SOURCE, which is repetitive and error prone. E.g.kselftest_harness.hrequires_GNU_SOURCEforasprintf(), but if a selftest includeskvm_test_harness.hafterstdio.h, the include guards result in the effective version ofstdio.hconsumed bykvm_test_harness.hnot definingasprintf():In file included from
x86_64/fix_hypercall_test.c:12:
In file included frominclude/kvm_test_harness.h:11:
../kselftest_harness.h:1169:2: error: call to undeclared function
'asprintf'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
Quoted 8 lines
1169 | asprintf(&test_name, "%s%s%s.%s", f->name, | ^When including the rseq selftest's "library" code, #undef
_GNU_SOURCEso thatrseq.ccontrols whether or not it wants to build with_GNU_SOURCE.Reported-by Muhammad Usama Anjum <[email protected]>Signed-off-by Sean Christopherson <[email protected]>
For KVM RISC-V:
Regards,
Anup
Quoted 824 lines
--- tools/testing/selftests/kvm/Makefile | 4 ++-- tools/testing/selftests/kvm/aarch64/arch_timer.c | 2 -- .../testing/selftests/kvm/aarch64/page_fault_test.c | 1 - tools/testing/selftests/kvm/aarch64/psci_test.c | 3 --- tools/testing/selftests/kvm/aarch64/vgic_init.c | 1 - tools/testing/selftests/kvm/arch_timer.c | 3 --- tools/testing/selftests/kvm/demand_paging_test.c | 3 --- tools/testing/selftests/kvm/dirty_log_test.c | 3 --- tools/testing/selftests/kvm/guest_memfd_test.c | 2 -- tools/testing/selftests/kvm/hardware_disable_test.c | 3 --- tools/testing/selftests/kvm/include/kvm_util_base.h | 12 ++++++------ .../testing/selftests/kvm/include/userfaultfd_util.h | 3 --- tools/testing/selftests/kvm/kvm_binary_stats_test.c | 2 -- tools/testing/selftests/kvm/kvm_create_max_vcpus.c | 2 -- tools/testing/selftests/kvm/kvm_page_table_test.c | 3 --- tools/testing/selftests/kvm/lib/assert.c | 3 --- tools/testing/selftests/kvm/lib/kvm_util.c | 2 -- tools/testing/selftests/kvm/lib/memstress.c | 2 -- tools/testing/selftests/kvm/lib/test_util.c | 2 -- tools/testing/selftests/kvm/lib/userfaultfd_util.c | 3 --- tools/testing/selftests/kvm/lib/x86_64/sev.c | 1 - tools/testing/selftests/kvm/max_guest_memory_test.c | 2 -- .../selftests/kvm/memslot_modification_stress_test.c | 3 --- tools/testing/selftests/kvm/riscv/arch_timer.c | 3 --- tools/testing/selftests/kvm/rseq_test.c | 12 +++++++++--- tools/testing/selftests/kvm/s390x/cmma_test.c | 2 -- tools/testing/selftests/kvm/s390x/sync_regs_test.c | 2 -- tools/testing/selftests/kvm/set_memory_region_test.c | 1 - tools/testing/selftests/kvm/steal_time.c | 1 - tools/testing/selftests/kvm/x86_64/amx_test.c | 2 -- .../kvm/x86_64/exit_on_emulation_failure_test.c | 3 --- tools/testing/selftests/kvm/x86_64/hwcr_msr_test.c | 2 -- tools/testing/selftests/kvm/x86_64/hyperv_cpuid.c | 2 -- tools/testing/selftests/kvm/x86_64/hyperv_evmcs.c | 1 - tools/testing/selftests/kvm/x86_64/hyperv_ipi.c | 2 -- tools/testing/selftests/kvm/x86_64/hyperv_svm_test.c | 1 - .../testing/selftests/kvm/x86_64/hyperv_tlb_flush.c | 2 -- .../selftests/kvm/x86_64/nested_exceptions_test.c | 2 -- .../selftests/kvm/x86_64/nx_huge_pages_test.c | 3 --- .../selftests/kvm/x86_64/platform_info_test.c | 2 -- .../testing/selftests/kvm/x86_64/pmu_counters_test.c | 2 -- .../selftests/kvm/x86_64/pmu_event_filter_test.c | 3 --- .../kvm/x86_64/private_mem_conversions_test.c | 1 - tools/testing/selftests/kvm/x86_64/set_boot_cpu_id.c | 1 - tools/testing/selftests/kvm/x86_64/set_sregs_test.c | 1 - .../kvm/x86_64/smaller_maxphyaddr_emulation_test.c | 3 --- tools/testing/selftests/kvm/x86_64/smm_test.c | 1 - tools/testing/selftests/kvm/x86_64/state_test.c | 1 - tools/testing/selftests/kvm/x86_64/sync_regs_test.c | 2 -- .../selftests/kvm/x86_64/ucna_injection_test.c | 2 -- .../selftests/kvm/x86_64/userspace_msr_exit_test.c | 2 -- .../selftests/kvm/x86_64/vmx_dirty_log_test.c | 3 --- .../testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c | 1 - .../selftests/kvm/x86_64/vmx_preemption_timer_test.c | 1 - tools/testing/selftests/kvm/x86_64/xapic_ipi_test.c | 2 -- .../testing/selftests/kvm/x86_64/xapic_state_test.c | 1 - tools/testing/selftests/kvm/x86_64/xss_msr_test.c | 2 -- 57 files changed, 17 insertions(+), 120 deletions(-)tools/testing/selftests/kvm/Makefile +2
-2@@ -226,8 +226,8 @@ LINUX_TOOL_ARCH_INCLUDE = $(top_srcdir)/tools/arch/$(ARCH)/include endif CFLAGS += -Wall -Wstrict-prototypes -Wuninitialized -O2 -g -std=gnu99 \ -Wno-gnu-variable-sized-type-not-at-end -MD -MP -DCONFIG_64BIT \ - -fno-builtin-memcmp -fno-builtin-memcpy -fno-builtin-memset \ - -fno-builtin-strnlen \ + -D_GNU_SOURCE -fno-builtin-memcmp -fno-builtin-memcpy \ + -fno-builtin-memset -fno-builtin-strnlen \ -fno-stack-protector -fno-PIE -I$(LINUX_TOOL_INCLUDE) \ -I$(LINUX_TOOL_ARCH_INCLUDE) -I$(LINUX_HDR_PATH) -Iinclude \ -I$(<D) -Iinclude/$(ARCH_DIR) -I ../rseq -I.. $(EXTRA_CFLAGS) \tools/testing/selftests/kvm/aarch64/arch_timer.c +0
-2@@ -5,8 +5,6 @@* * Copyright (c) 2021, Google LLC. */ -#define _GNU_SOURCE -#include "arch_timer.h" #include "delay.h" #include "gic.h" tools/testing/selftests/kvm/aarch64/page_fault_test.c +0
-1@@ -7,7 +7,6 @@* 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). */ -#define _GNU_SOURCE#include <linux/bitmap.h> #include <fcntl.h> #include <test_util.h> tools/testing/selftests/kvm/aarch64/psci_test.c +0
-3@@ -10,9 +10,6 @@* - A test for KVM's handling of PSCI SYSTEM_SUSPEND and the associated * KVM_SYSTEM_EVENT_SUSPEND UAPI. */ - -#define _GNU_SOURCE -#include <linux/psci.h> #include "kvm_util.h" tools/testing/selftests/kvm/aarch64/vgic_init.c +0
-1@@ -4,7 +4,6 @@* * Copyright (C) 2020, Red Hat, Inc. */ -#define _GNU_SOURCE#include <linux/kernel.h> #include <sys/syscall.h> #include <asm/kvm.h> tools/testing/selftests/kvm/arch_timer.c +0
-3@@ -19,9 +19,6 @@* * Copyright (c) 2021, Google LLC. */ - -#define _GNU_SOURCE -#include <stdlib.h> #include <pthread.h> #include <linux/sizes.h> tools/testing/selftests/kvm/demand_paging_test.c +0
-3@@ -6,9 +6,6 @@* Copyright (C) 2018, Red Hat, Inc. * Copyright (C) 2019, Google, Inc. */ - -#define _GNU_SOURCE/* for pipe2 */ -#include <inttypes.h> #include <stdio.h> #include <stdlib.h> tools/testing/selftests/kvm/dirty_log_test.c +0
-3@@ -4,9 +4,6 @@* * Copyright (C) 2018, Red Hat, Inc. */ - -#define _GNU_SOURCE/* for program_invocation_name */ -#include <stdio.h> #include <stdlib.h> #include <pthread.h> tools/testing/selftests/kvm/guest_memfd_test.c +0
-2@@ -4,8 +4,6 @@* * Author: Chao Peng <[email protected]> */ - -#define _GNU_SOURCE#include <stdlib.h> #include <string.h> #include <unistd.h> tools/testing/selftests/kvm/hardware_disable_test.c +0
-3@@ -4,9 +4,6 @@* kvm_arch_hardware_disable is called and it attempts to unregister the user * return notifiers. */ - -#define _GNU_SOURCE -#include <fcntl.h> #include <pthread.h> #include <semaphore.h> tools/testing/selftests/kvm/include/kvm_util_base.h +6
-6@@ -27,12 +27,12 @@/* * 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) -* #undefs and #defines static_assert() as a direct alias to _Static_assert(), -* i.e. effectively makes the message mandatory. Many KVM selftests #define -* _GNU_SOURCE for various reasons, and _GNU_SOURCE implies _ISOC11_SOURCE. As -* a result, static_assert() behavior is non-deterministic and may or may not -* require a message depending on #include order. +* 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)tools/testing/selftests/kvm/include/userfaultfd_util.h +0
-3@@ -5,9 +5,6 @@* Copyright (C) 2018, Red Hat, Inc. * Copyright (C) 2019-2022 Google LLC */ - -#define _GNU_SOURCE/* for pipe2 */ -#include <inttypes.h> #include <time.h> #include <pthread.h> tools/testing/selftests/kvm/kvm_binary_stats_test.c +0
-2@@ -6,8 +6,6 @@* * Test the fd-based interface for KVM statistics. */ - -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <fcntl.h> #include <stdio.h> #include <stdlib.h> tools/testing/selftests/kvm/kvm_create_max_vcpus.c +0
-2@@ -6,8 +6,6 @@* * Test for KVM_CAP_MAX_VCPUS and KVM_CAP_MAX_VCPU_ID. */ - -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <fcntl.h> #include <stdio.h> #include <stdlib.h> tools/testing/selftests/kvm/kvm_page_table_test.c +0
-3@@ -8,9 +8,6 @@* page size have been pre-allocated on your system, if you are planning to * use hugepages to back the guest memory for testing. */ - -#define _GNU_SOURCE/* for program_invocation_name */ -#include <stdio.h> #include <stdlib.h> #include <time.h> tools/testing/selftests/kvm/lib/assert.c +0
-3@@ -4,9 +4,6 @@* * Copyright (C) 2018, Google LLC. */ - -#define _GNU_SOURCE/* for getline(3) and strchrnul(3)*/ -#include "test_util.h" #include <execinfo.h> tools/testing/selftests/kvm/lib/kvm_util.c +0
-2@@ -4,8 +4,6 @@* * Copyright (C) 2018, Google LLC. */ - -#define _GNU_SOURCE/* for program_invocation_name */ #include "test_util.h" #include "kvm_util.h" #include "processor.h" tools/testing/selftests/kvm/lib/memstress.c +0
-2@@ -2,8 +2,6 @@/* * Copyright (C) 2020, Google LLC. */ -#define _GNU_SOURCE -#include <inttypes.h> #include <linux/bitmap.h> tools/testing/selftests/kvm/lib/test_util.c +0
-2@@ -4,8 +4,6 @@* * Copyright (C) 2020, Google LLC. */ - -#define _GNU_SOURCE#include <stdio.h> #include <stdarg.h> #include <assert.h> tools/testing/selftests/kvm/lib/userfaultfd_util.c +0
-3@@ -6,9 +6,6 @@* Copyright (C) 2018, Red Hat, Inc. * Copyright (C) 2019-2022 Google LLC */ - -#define _GNU_SOURCE/* for pipe2 */ -#include <inttypes.h> #include <stdio.h> #include <stdlib.h> tools/testing/selftests/kvm/lib/x86_64/sev.c +0
-1@@ -1,5 +1,4 @@// SPDX-License-Identifier: GPL-2.0-only -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <stdint.h> #include <stdbool.h> tools/testing/selftests/kvm/max_guest_memory_test.c +0
-2@@ -1,6 +1,4 @@// SPDX-License-Identifier: GPL-2.0 -#define _GNU_SOURCE -#include <stdio.h> #include <stdlib.h> #include <pthread.h> tools/testing/selftests/kvm/memslot_modification_stress_test.c +0
-3@@ -6,9 +6,6 @@* Copyright (C) 2018, Red Hat, Inc. * Copyright (C) 2020, Google, Inc. */ - -#define _GNU_SOURCE/* for program_invocation_name */ -#include <stdio.h> #include <stdlib.h> #include <sys/syscall.h> tools/testing/selftests/kvm/riscv/arch_timer.c +0
-3@@ -7,9 +7,6 @@* * Copyright (c) 2024, Intel Corporation. */ - -#define _GNU_SOURCE -#include "arch_timer.h" #include "kvm_util.h" #include "processor.h" tools/testing/selftests/kvm/rseq_test.c +9
-3@@ -1,5 +1,13 @@// 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 <fcntl.h> #include <pthread.h> @@ -20,8 +28,6 @@#include "processor.h" #include "test_util.h" -#include "../rseq/rseq.c" -/* * Any bug related to task migration is likely to be timing-dependent; perform * a large number of migrations to reduce the odds of a false negative. tools/testing/selftests/kvm/s390x/cmma_test.c +0
-2@@ -7,8 +7,6 @@* Authors: * Nico Boehr <[email protected]> */ - -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <fcntl.h> #include <stdio.h> #include <stdlib.h> tools/testing/selftests/kvm/s390x/sync_regs_test.c +0
-2@@ -10,8 +10,6 @@* * Test expected behavior of the KVM_CAP_SYNC_REGS functionality. */ - -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <fcntl.h> #include <stdio.h> #include <stdlib.h> tools/testing/selftests/kvm/set_memory_region_test.c +0
-1@@ -1,5 +1,4 @@// SPDX-License-Identifier: GPL-2.0 -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <fcntl.h> #include <pthread.h> #include <sched.h> tools/testing/selftests/kvm/steal_time.c +0
-1@@ -4,7 +4,6 @@* * Copyright (C) 2020, Red Hat, Inc. */ -#define _GNU_SOURCE#include <stdio.h> #include <time.h> #include <sched.h> tools/testing/selftests/kvm/x86_64/amx_test.c +0
-2@@ -6,8 +6,6 @@* * Tests for amx #NM exception and save/restore. */ - -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <fcntl.h> #include <stdio.h> #include <stdlib.h> tools/testing/selftests/kvm/x86_64/exit_on_emulation_failure_test.c +0
-3@@ -4,9 +4,6 @@* * Test for KVM_CAP_EXIT_ON_EMULATION_FAILURE. */ - -#define _GNU_SOURCE/* for program_invocation_short_name */ -#include "flds_emulation.h" #include "test_util.h" tools/testing/selftests/kvm/x86_64/hwcr_msr_test.c +0
-2@@ -2,8 +2,6 @@/* * Copyright (C) 2023, Google LLC. */ - -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <sys/ioctl.h> #include "test_util.h" tools/testing/selftests/kvm/x86_64/hyperv_cpuid.c +0
-2@@ -7,8 +7,6 @@* 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 <stdio.h> #include <stdlib.h> tools/testing/selftests/kvm/x86_64/hyperv_evmcs.c +0
-1@@ -4,7 +4,6 @@* * Tests for Enlightened VMCS, including nested guest state. */ -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <fcntl.h> #include <stdio.h> #include <stdlib.h> tools/testing/selftests/kvm/x86_64/hyperv_ipi.c +0
-2@@ -5,8 +5,6 @@* Copyright (C) 2022, Red Hat, Inc. * */ - -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <pthread.h> #include <inttypes.h> tools/testing/selftests/kvm/x86_64/hyperv_svm_test.c +0
-1@@ -4,7 +4,6 @@* * Tests for Hyper-V extensions to SVM. */ -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <fcntl.h> #include <stdio.h> #include <stdlib.h> tools/testing/selftests/kvm/x86_64/hyperv_tlb_flush.c +0
-2@@ -5,8 +5,6 @@* Copyright (C) 2022, Red Hat, Inc. * */ - -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <asm/barrier.h> #include <pthread.h> #include <inttypes.h> tools/testing/selftests/kvm/x86_64/nested_exceptions_test.c +0
-2@@ -1,6 +1,4 @@// SPDX-License-Identifier: GPL-2.0-only -#define _GNU_SOURCE/* for program_invocation_short_name */ -#include "test_util.h" #include "kvm_util.h" #include "processor.h" tools/testing/selftests/kvm/x86_64/nx_huge_pages_test.c +0
-3@@ -5,9 +5,6 @@* * Copyright (C) 2022, Google LLC. */ - -#define _GNU_SOURCE -#include <fcntl.h> #include <stdint.h> #include <time.h> tools/testing/selftests/kvm/x86_64/platform_info_test.c +0
-2@@ -9,8 +9,6 @@* Verifies expected behavior of controlling guest access to * MSR_PLATFORM_INFO. */ - -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <fcntl.h> #include <stdio.h> #include <stdlib.h> tools/testing/selftests/kvm/x86_64/pmu_counters_test.c +0
-2@@ -2,8 +2,6 @@/* * Copyright (C) 2023, Tencent, Inc. */ - -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <x86intrin.h> #include "pmu.h" tools/testing/selftests/kvm/x86_64/pmu_event_filter_test.c +0
-3@@ -9,9 +9,6 @@* Verifies the expected behavior of allow lists and deny lists for * virtual PMU events. */ - -#define _GNU_SOURCE/* for program_invocation_short_name */ -#include "kvm_util.h" #include "pmu.h" #include "processor.h" tools/testing/selftests/kvm/x86_64/private_mem_conversions_test.c +0
-1@@ -2,7 +2,6 @@/* * Copyright (C) 2022, Google LLC. */ -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <fcntl.h> #include <limits.h> #include <pthread.h> tools/testing/selftests/kvm/x86_64/set_boot_cpu_id.c +0
-1@@ -4,7 +4,6 @@* * Copyright (C) 2020, Red Hat, Inc. */ -#define _GNU_SOURCE/* for program_invocation_name */ #include <fcntl.h> #include <stdio.h> #include <stdlib.h> tools/testing/selftests/kvm/x86_64/set_sregs_test.c +0
-1@@ -10,7 +10,6 @@* 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. */ -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <fcntl.h> #include <stdio.h> #include <stdlib.h> tools/testing/selftests/kvm/x86_64/smaller_maxphyaddr_emulation_test.c +0
-3@@ -5,9 +5,6 @@* Test that KVM emulates instructions in response to EPT violations when * allow_smaller_maxphyaddr is enabled and guest.MAXPHYADDR < host.MAXPHYADDR. */ - -#define _GNU_SOURCE/* for program_invocation_short_name */ -#include "flds_emulation.h" #include "test_util.h" tools/testing/selftests/kvm/x86_64/smm_test.c +0
-1@@ -4,7 +4,6 @@* * Tests for SMM. */ -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <fcntl.h> #include <stdio.h> #include <stdlib.h> tools/testing/selftests/kvm/x86_64/state_test.c +0
-1@@ -6,7 +6,6 @@* * Tests for vCPU state save/restore, including nested guest state. */ -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <fcntl.h> #include <stdio.h> #include <stdlib.h> tools/testing/selftests/kvm/x86_64/sync_regs_test.c +0
-2@@ -8,8 +8,6 @@* 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. */ - -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <fcntl.h> #include <stdio.h> #include <stdlib.h> tools/testing/selftests/kvm/x86_64/ucna_injection_test.c +0
-2@@ -17,8 +17,6 @@* delivered into the guest or not. * */ - -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <pthread.h> #include <inttypes.h> #include <string.h> tools/testing/selftests/kvm/x86_64/userspace_msr_exit_test.c +0
-2@@ -4,8 +4,6 @@* * Tests for exiting into userspace on registered MSRs */ - -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <sys/ioctl.h> #include "kvm_test_harness.h" tools/testing/selftests/kvm/x86_64/vmx_dirty_log_test.c +0
-3@@ -4,9 +4,6 @@* * Copyright (C) 2018, Red Hat, Inc. */ - -#define _GNU_SOURCE/* for program_invocation_name */ -#include <stdio.h> #include <stdlib.h> #include <linux/bitmap.h> tools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c +0
-1@@ -10,7 +10,6 @@* and check it can be retrieved with KVM_GET_MSR, also test * the invalid LBR formats are rejected. */ -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <sys/ioctl.h> #include <linux/bitmap.h> tools/testing/selftests/kvm/x86_64/vmx_preemption_timer_test.c +0
-1@@ -9,7 +9,6 @@* value instead of partially decayed timer value * */ -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <fcntl.h> #include <stdio.h> #include <stdlib.h> tools/testing/selftests/kvm/x86_64/xapic_ipi_test.c +0
-2@@ -19,8 +19,6 @@* 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. */ - -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <getopt.h> #include <pthread.h> #include <inttypes.h> tools/testing/selftests/kvm/x86_64/xapic_state_test.c +0
-1@@ -1,5 +1,4 @@// SPDX-License-Identifier: GPL-2.0-only -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <fcntl.h> #include <stdio.h> #include <stdlib.h> tools/testing/selftests/kvm/x86_64/xss_msr_test.c +0
-2@@ -4,8 +4,6 @@* * Tests for the IA32_XSS MSR. */ - -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <sys/ioctl.h> #include "test_util.h" base-commit:
7b076c6a308ec5bce9fc96e2935443ed228b9148--
2.44.0.769.g3c40516874-goog
Quoted 12 lines · On Tue, 23 Apr 2024 12:03:08 -0700 Sean Christopherson <[email protected]>…
Define
_GNU_SOURCEis the base CFLAGS instead of relying on selftests to manually #define_GNU_SOURCE, which is repetitive and error prone. E.g.kselftest_harness.hrequires_GNU_SOURCEforasprintf(), but if a selftest includeskvm_test_harness.hafterstdio.h, the include guards result in the effective version ofstdio.hconsumed bykvm_test_harness.hnot definingasprintf():In file included from
x86_64/fix_hypercall_test.c:12:
In file included frominclude/kvm_test_harness.h:11:
../kselftest_harness.h:1169:2: error: call to undeclared function
'asprintf'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
Quoted 8 lines
1169 | asprintf(&test_name, "%s%s%s.%s", f->name, | ^When including the rseq selftest's "library" code, #undef
_GNU_SOURCEso thatrseq.ccontrols whether or not it wants to build with_GNU_SOURCE.Reported-by Muhammad Usama Anjum <[email protected]>Signed-off-by Sean Christopherson <[email protected]>
for s390:
Quoted 821 lines
--- tools/testing/selftests/kvm/Makefile | 4 ++-- tools/testing/selftests/kvm/aarch64/arch_timer.c | 2 -- .../testing/selftests/kvm/aarch64/page_fault_test.c | 1 - tools/testing/selftests/kvm/aarch64/psci_test.c | 3 --- tools/testing/selftests/kvm/aarch64/vgic_init.c | 1 - tools/testing/selftests/kvm/arch_timer.c | 3 --- tools/testing/selftests/kvm/demand_paging_test.c | 3 --- tools/testing/selftests/kvm/dirty_log_test.c | 3 --- tools/testing/selftests/kvm/guest_memfd_test.c | 2 -- tools/testing/selftests/kvm/hardware_disable_test.c | 3 --- tools/testing/selftests/kvm/include/kvm_util_base.h | 12 ++++++------ .../testing/selftests/kvm/include/userfaultfd_util.h | 3 --- tools/testing/selftests/kvm/kvm_binary_stats_test.c | 2 -- tools/testing/selftests/kvm/kvm_create_max_vcpus.c | 2 -- tools/testing/selftests/kvm/kvm_page_table_test.c | 3 --- tools/testing/selftests/kvm/lib/assert.c | 3 --- tools/testing/selftests/kvm/lib/kvm_util.c | 2 -- tools/testing/selftests/kvm/lib/memstress.c | 2 -- tools/testing/selftests/kvm/lib/test_util.c | 2 -- tools/testing/selftests/kvm/lib/userfaultfd_util.c | 3 --- tools/testing/selftests/kvm/lib/x86_64/sev.c | 1 - tools/testing/selftests/kvm/max_guest_memory_test.c | 2 -- .../selftests/kvm/memslot_modification_stress_test.c | 3 --- tools/testing/selftests/kvm/riscv/arch_timer.c | 3 --- tools/testing/selftests/kvm/rseq_test.c | 12 +++++++++--- tools/testing/selftests/kvm/s390x/cmma_test.c | 2 -- tools/testing/selftests/kvm/s390x/sync_regs_test.c | 2 -- tools/testing/selftests/kvm/set_memory_region_test.c | 1 - tools/testing/selftests/kvm/steal_time.c | 1 - tools/testing/selftests/kvm/x86_64/amx_test.c | 2 -- .../kvm/x86_64/exit_on_emulation_failure_test.c | 3 --- tools/testing/selftests/kvm/x86_64/hwcr_msr_test.c | 2 -- tools/testing/selftests/kvm/x86_64/hyperv_cpuid.c | 2 -- tools/testing/selftests/kvm/x86_64/hyperv_evmcs.c | 1 - tools/testing/selftests/kvm/x86_64/hyperv_ipi.c | 2 -- tools/testing/selftests/kvm/x86_64/hyperv_svm_test.c | 1 - .../testing/selftests/kvm/x86_64/hyperv_tlb_flush.c | 2 -- .../selftests/kvm/x86_64/nested_exceptions_test.c | 2 -- .../selftests/kvm/x86_64/nx_huge_pages_test.c | 3 --- .../selftests/kvm/x86_64/platform_info_test.c | 2 -- .../testing/selftests/kvm/x86_64/pmu_counters_test.c | 2 -- .../selftests/kvm/x86_64/pmu_event_filter_test.c | 3 --- .../kvm/x86_64/private_mem_conversions_test.c | 1 - tools/testing/selftests/kvm/x86_64/set_boot_cpu_id.c | 1 - tools/testing/selftests/kvm/x86_64/set_sregs_test.c | 1 - .../kvm/x86_64/smaller_maxphyaddr_emulation_test.c | 3 --- tools/testing/selftests/kvm/x86_64/smm_test.c | 1 - tools/testing/selftests/kvm/x86_64/state_test.c | 1 - tools/testing/selftests/kvm/x86_64/sync_regs_test.c | 2 -- .../selftests/kvm/x86_64/ucna_injection_test.c | 2 -- .../selftests/kvm/x86_64/userspace_msr_exit_test.c | 2 -- .../selftests/kvm/x86_64/vmx_dirty_log_test.c | 3 --- .../testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c | 1 - .../selftests/kvm/x86_64/vmx_preemption_timer_test.c | 1 - tools/testing/selftests/kvm/x86_64/xapic_ipi_test.c | 2 -- .../testing/selftests/kvm/x86_64/xapic_state_test.c | 1 - tools/testing/selftests/kvm/x86_64/xss_msr_test.c | 2 -- 57 files changed, 17 insertions(+), 120 deletions(-)tools/testing/selftests/kvm/Makefile +2
-2@@ -226,8 +226,8 @@ LINUX_TOOL_ARCH_INCLUDE = $(top_srcdir)/tools/arch/$(ARCH)/include endif CFLAGS += -Wall -Wstrict-prototypes -Wuninitialized -O2 -g -std=gnu99 \ -Wno-gnu-variable-sized-type-not-at-end -MD -MP -DCONFIG_64BIT \ - -fno-builtin-memcmp -fno-builtin-memcpy -fno-builtin-memset \ - -fno-builtin-strnlen \ + -D_GNU_SOURCE -fno-builtin-memcmp -fno-builtin-memcpy \ + -fno-builtin-memset -fno-builtin-strnlen \ -fno-stack-protector -fno-PIE -I$(LINUX_TOOL_INCLUDE) \ -I$(LINUX_TOOL_ARCH_INCLUDE) -I$(LINUX_HDR_PATH) -Iinclude \ -I$(<D) -Iinclude/$(ARCH_DIR) -I ../rseq -I.. $(EXTRA_CFLAGS) \tools/testing/selftests/kvm/aarch64/arch_timer.c +0
-2@@ -5,8 +5,6 @@* * Copyright (c) 2021, Google LLC. */ -#define _GNU_SOURCE -#include "arch_timer.h" #include "delay.h" #include "gic.h" tools/testing/selftests/kvm/aarch64/page_fault_test.c +0
-1@@ -7,7 +7,6 @@* 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). */ -#define _GNU_SOURCE#include <linux/bitmap.h> #include <fcntl.h> #include <test_util.h> tools/testing/selftests/kvm/aarch64/psci_test.c +0
-3@@ -10,9 +10,6 @@* - A test for KVM's handling of PSCI SYSTEM_SUSPEND and the associated * KVM_SYSTEM_EVENT_SUSPEND UAPI. */ - -#define _GNU_SOURCE -#include <linux/psci.h> #include "kvm_util.h" tools/testing/selftests/kvm/aarch64/vgic_init.c +0
-1@@ -4,7 +4,6 @@* * Copyright (C) 2020, Red Hat, Inc. */ -#define _GNU_SOURCE#include <linux/kernel.h> #include <sys/syscall.h> #include <asm/kvm.h> tools/testing/selftests/kvm/arch_timer.c +0
-3@@ -19,9 +19,6 @@* * Copyright (c) 2021, Google LLC. */ - -#define _GNU_SOURCE -#include <stdlib.h> #include <pthread.h> #include <linux/sizes.h> tools/testing/selftests/kvm/demand_paging_test.c +0
-3@@ -6,9 +6,6 @@* Copyright (C) 2018, Red Hat, Inc. * Copyright (C) 2019, Google, Inc. */ - -#define _GNU_SOURCE/* for pipe2 */ -#include <inttypes.h> #include <stdio.h> #include <stdlib.h> tools/testing/selftests/kvm/dirty_log_test.c +0
-3@@ -4,9 +4,6 @@* * Copyright (C) 2018, Red Hat, Inc. */ - -#define _GNU_SOURCE/* for program_invocation_name */ -#include <stdio.h> #include <stdlib.h> #include <pthread.h> tools/testing/selftests/kvm/guest_memfd_test.c +0
-2@@ -4,8 +4,6 @@* * Author: Chao Peng <[email protected]> */ - -#define _GNU_SOURCE#include <stdlib.h> #include <string.h> #include <unistd.h> tools/testing/selftests/kvm/hardware_disable_test.c +0
-3@@ -4,9 +4,6 @@* kvm_arch_hardware_disable is called and it attempts to unregister the user * return notifiers. */ - -#define _GNU_SOURCE -#include <fcntl.h> #include <pthread.h> #include <semaphore.h> tools/testing/selftests/kvm/include/kvm_util_base.h +6
-6@@ -27,12 +27,12 @@/* * 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) -* #undefs and #defines static_assert() as a direct alias to _Static_assert(), -* i.e. effectively makes the message mandatory. Many KVM selftests #define -* _GNU_SOURCE for various reasons, and _GNU_SOURCE implies _ISOC11_SOURCE. As -* a result, static_assert() behavior is non-deterministic and may or may not -* require a message depending on #include order. +* 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)tools/testing/selftests/kvm/include/userfaultfd_util.h +0
-3@@ -5,9 +5,6 @@* Copyright (C) 2018, Red Hat, Inc. * Copyright (C) 2019-2022 Google LLC */ - -#define _GNU_SOURCE/* for pipe2 */ -#include <inttypes.h> #include <time.h> #include <pthread.h> tools/testing/selftests/kvm/kvm_binary_stats_test.c +0
-2@@ -6,8 +6,6 @@* * Test the fd-based interface for KVM statistics. */ - -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <fcntl.h> #include <stdio.h> #include <stdlib.h> tools/testing/selftests/kvm/kvm_create_max_vcpus.c +0
-2@@ -6,8 +6,6 @@* * Test for KVM_CAP_MAX_VCPUS and KVM_CAP_MAX_VCPU_ID. */ - -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <fcntl.h> #include <stdio.h> #include <stdlib.h> tools/testing/selftests/kvm/kvm_page_table_test.c +0
-3@@ -8,9 +8,6 @@* page size have been pre-allocated on your system, if you are planning to * use hugepages to back the guest memory for testing. */ - -#define _GNU_SOURCE/* for program_invocation_name */ -#include <stdio.h> #include <stdlib.h> #include <time.h> tools/testing/selftests/kvm/lib/assert.c +0
-3@@ -4,9 +4,6 @@* * Copyright (C) 2018, Google LLC. */ - -#define _GNU_SOURCE/* for getline(3) and strchrnul(3)*/ -#include "test_util.h" #include <execinfo.h> tools/testing/selftests/kvm/lib/kvm_util.c +0
-2@@ -4,8 +4,6 @@* * Copyright (C) 2018, Google LLC. */ - -#define _GNU_SOURCE/* for program_invocation_name */ #include "test_util.h" #include "kvm_util.h" #include "processor.h" tools/testing/selftests/kvm/lib/memstress.c +0
-2@@ -2,8 +2,6 @@/* * Copyright (C) 2020, Google LLC. */ -#define _GNU_SOURCE -#include <inttypes.h> #include <linux/bitmap.h> tools/testing/selftests/kvm/lib/test_util.c +0
-2@@ -4,8 +4,6 @@* * Copyright (C) 2020, Google LLC. */ - -#define _GNU_SOURCE#include <stdio.h> #include <stdarg.h> #include <assert.h> tools/testing/selftests/kvm/lib/userfaultfd_util.c +0
-3@@ -6,9 +6,6 @@* Copyright (C) 2018, Red Hat, Inc. * Copyright (C) 2019-2022 Google LLC */ - -#define _GNU_SOURCE/* for pipe2 */ -#include <inttypes.h> #include <stdio.h> #include <stdlib.h> tools/testing/selftests/kvm/lib/x86_64/sev.c +0
-1@@ -1,5 +1,4 @@// SPDX-License-Identifier: GPL-2.0-only -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <stdint.h> #include <stdbool.h> tools/testing/selftests/kvm/max_guest_memory_test.c +0
-2@@ -1,6 +1,4 @@// SPDX-License-Identifier: GPL-2.0 -#define _GNU_SOURCE -#include <stdio.h> #include <stdlib.h> #include <pthread.h> tools/testing/selftests/kvm/memslot_modification_stress_test.c +0
-3@@ -6,9 +6,6 @@* Copyright (C) 2018, Red Hat, Inc. * Copyright (C) 2020, Google, Inc. */ - -#define _GNU_SOURCE/* for program_invocation_name */ -#include <stdio.h> #include <stdlib.h> #include <sys/syscall.h> tools/testing/selftests/kvm/riscv/arch_timer.c +0
-3@@ -7,9 +7,6 @@* * Copyright (c) 2024, Intel Corporation. */ - -#define _GNU_SOURCE -#include "arch_timer.h" #include "kvm_util.h" #include "processor.h" tools/testing/selftests/kvm/rseq_test.c +9
-3@@ -1,5 +1,13 @@// 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 <fcntl.h> #include <pthread.h> @@ -20,8 +28,6 @@#include "processor.h" #include "test_util.h" -#include "../rseq/rseq.c" -/* * Any bug related to task migration is likely to be timing-dependent; perform * a large number of migrations to reduce the odds of a false negative. tools/testing/selftests/kvm/s390x/cmma_test.c +0
-2@@ -7,8 +7,6 @@* Authors: * Nico Boehr <[email protected]> */ - -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <fcntl.h> #include <stdio.h> #include <stdlib.h> tools/testing/selftests/kvm/s390x/sync_regs_test.c +0
-2@@ -10,8 +10,6 @@* * Test expected behavior of the KVM_CAP_SYNC_REGS functionality. */ - -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <fcntl.h> #include <stdio.h> #include <stdlib.h> tools/testing/selftests/kvm/set_memory_region_test.c +0
-1@@ -1,5 +1,4 @@// SPDX-License-Identifier: GPL-2.0 -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <fcntl.h> #include <pthread.h> #include <sched.h> tools/testing/selftests/kvm/steal_time.c +0
-1@@ -4,7 +4,6 @@* * Copyright (C) 2020, Red Hat, Inc. */ -#define _GNU_SOURCE#include <stdio.h> #include <time.h> #include <sched.h> tools/testing/selftests/kvm/x86_64/amx_test.c +0
-2@@ -6,8 +6,6 @@* * Tests for amx #NM exception and save/restore. */ - -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <fcntl.h> #include <stdio.h> #include <stdlib.h> tools/testing/selftests/kvm/x86_64/exit_on_emulation_failure_test.c +0
-3@@ -4,9 +4,6 @@* * Test for KVM_CAP_EXIT_ON_EMULATION_FAILURE. */ - -#define _GNU_SOURCE/* for program_invocation_short_name */ -#include "flds_emulation.h" #include "test_util.h" tools/testing/selftests/kvm/x86_64/hwcr_msr_test.c +0
-2@@ -2,8 +2,6 @@/* * Copyright (C) 2023, Google LLC. */ - -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <sys/ioctl.h> #include "test_util.h" tools/testing/selftests/kvm/x86_64/hyperv_cpuid.c +0
-2@@ -7,8 +7,6 @@* 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 <stdio.h> #include <stdlib.h> tools/testing/selftests/kvm/x86_64/hyperv_evmcs.c +0
-1@@ -4,7 +4,6 @@* * Tests for Enlightened VMCS, including nested guest state. */ -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <fcntl.h> #include <stdio.h> #include <stdlib.h> tools/testing/selftests/kvm/x86_64/hyperv_ipi.c +0
-2@@ -5,8 +5,6 @@* Copyright (C) 2022, Red Hat, Inc. * */ - -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <pthread.h> #include <inttypes.h> tools/testing/selftests/kvm/x86_64/hyperv_svm_test.c +0
-1@@ -4,7 +4,6 @@* * Tests for Hyper-V extensions to SVM. */ -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <fcntl.h> #include <stdio.h> #include <stdlib.h> tools/testing/selftests/kvm/x86_64/hyperv_tlb_flush.c +0
-2@@ -5,8 +5,6 @@* Copyright (C) 2022, Red Hat, Inc. * */ - -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <asm/barrier.h> #include <pthread.h> #include <inttypes.h> tools/testing/selftests/kvm/x86_64/nested_exceptions_test.c +0
-2@@ -1,6 +1,4 @@// SPDX-License-Identifier: GPL-2.0-only -#define _GNU_SOURCE/* for program_invocation_short_name */ -#include "test_util.h" #include "kvm_util.h" #include "processor.h" tools/testing/selftests/kvm/x86_64/nx_huge_pages_test.c +0
-3@@ -5,9 +5,6 @@* * Copyright (C) 2022, Google LLC. */ - -#define _GNU_SOURCE -#include <fcntl.h> #include <stdint.h> #include <time.h> tools/testing/selftests/kvm/x86_64/platform_info_test.c +0
-2@@ -9,8 +9,6 @@* Verifies expected behavior of controlling guest access to * MSR_PLATFORM_INFO. */ - -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <fcntl.h> #include <stdio.h> #include <stdlib.h> tools/testing/selftests/kvm/x86_64/pmu_counters_test.c +0
-2@@ -2,8 +2,6 @@/* * Copyright (C) 2023, Tencent, Inc. */ - -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <x86intrin.h> #include "pmu.h" tools/testing/selftests/kvm/x86_64/pmu_event_filter_test.c +0
-3@@ -9,9 +9,6 @@* Verifies the expected behavior of allow lists and deny lists for * virtual PMU events. */ - -#define _GNU_SOURCE/* for program_invocation_short_name */ -#include "kvm_util.h" #include "pmu.h" #include "processor.h" tools/testing/selftests/kvm/x86_64/private_mem_conversions_test.c +0
-1@@ -2,7 +2,6 @@/* * Copyright (C) 2022, Google LLC. */ -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <fcntl.h> #include <limits.h> #include <pthread.h> tools/testing/selftests/kvm/x86_64/set_boot_cpu_id.c +0
-1@@ -4,7 +4,6 @@* * Copyright (C) 2020, Red Hat, Inc. */ -#define _GNU_SOURCE/* for program_invocation_name */ #include <fcntl.h> #include <stdio.h> #include <stdlib.h> tools/testing/selftests/kvm/x86_64/set_sregs_test.c +0
-1@@ -10,7 +10,6 @@* 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. */ -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <fcntl.h> #include <stdio.h> #include <stdlib.h> tools/testing/selftests/kvm/x86_64/smaller_maxphyaddr_emulation_test.c +0
-3@@ -5,9 +5,6 @@* Test that KVM emulates instructions in response to EPT violations when * allow_smaller_maxphyaddr is enabled and guest.MAXPHYADDR < host.MAXPHYADDR. */ - -#define _GNU_SOURCE/* for program_invocation_short_name */ -#include "flds_emulation.h" #include "test_util.h" tools/testing/selftests/kvm/x86_64/smm_test.c +0
-1@@ -4,7 +4,6 @@* * Tests for SMM. */ -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <fcntl.h> #include <stdio.h> #include <stdlib.h> tools/testing/selftests/kvm/x86_64/state_test.c +0
-1@@ -6,7 +6,6 @@* * Tests for vCPU state save/restore, including nested guest state. */ -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <fcntl.h> #include <stdio.h> #include <stdlib.h> tools/testing/selftests/kvm/x86_64/sync_regs_test.c +0
-2@@ -8,8 +8,6 @@* 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. */ - -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <fcntl.h> #include <stdio.h> #include <stdlib.h> tools/testing/selftests/kvm/x86_64/ucna_injection_test.c +0
-2@@ -17,8 +17,6 @@* delivered into the guest or not. * */ - -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <pthread.h> #include <inttypes.h> #include <string.h> tools/testing/selftests/kvm/x86_64/userspace_msr_exit_test.c +0
-2@@ -4,8 +4,6 @@* * Tests for exiting into userspace on registered MSRs */ - -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <sys/ioctl.h> #include "kvm_test_harness.h" tools/testing/selftests/kvm/x86_64/vmx_dirty_log_test.c +0
-3@@ -4,9 +4,6 @@* * Copyright (C) 2018, Red Hat, Inc. */ - -#define _GNU_SOURCE/* for program_invocation_name */ -#include <stdio.h> #include <stdlib.h> #include <linux/bitmap.h> tools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c +0
-1@@ -10,7 +10,6 @@* and check it can be retrieved with KVM_GET_MSR, also test * the invalid LBR formats are rejected. */ -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <sys/ioctl.h> #include <linux/bitmap.h> tools/testing/selftests/kvm/x86_64/vmx_preemption_timer_test.c +0
-1@@ -9,7 +9,6 @@* value instead of partially decayed timer value * */ -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <fcntl.h> #include <stdio.h> #include <stdlib.h> tools/testing/selftests/kvm/x86_64/xapic_ipi_test.c +0
-2@@ -19,8 +19,6 @@* 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. */ - -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <getopt.h> #include <pthread.h> #include <inttypes.h> tools/testing/selftests/kvm/x86_64/xapic_state_test.c +0
-1@@ -1,5 +1,4 @@// SPDX-License-Identifier: GPL-2.0-only -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <fcntl.h> #include <stdio.h> #include <stdlib.h> tools/testing/selftests/kvm/x86_64/xss_msr_test.c +0
-2@@ -4,8 +4,6 @@* * Tests for the IA32_XSS MSR. */ - -#define _GNU_SOURCE/* for program_invocation_short_name */ #include <sys/ioctl.h> #include "test_util.h" base-commit:
7b076c6a308ec5bce9fc96e2935443ed228b9148
Quoted 12 lines · Sean Christopherson
Define
_GNU_SOURCEis the base CFLAGS instead of relying on selftests to manually #define_GNU_SOURCE, which is repetitive and error prone. E.g.kselftest_harness.hrequires_GNU_SOURCEforasprintf(), but if a selftest includeskvm_test_harness.hafterstdio.h, the include guards result in the effective version ofstdio.hconsumed bykvm_test_harness.hnot definingasprintf():In file included from
x86_64/fix_hypercall_test.c:12:
In file included frominclude/kvm_test_harness.h:11:
../kselftest_harness.h:1169:2: error: call to undeclared function
'asprintf'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
Quoted 8 lines
1169 | asprintf(&test_name, "%s%s%s.%s", f->name, | ^When including the rseq selftest's "library" code, #undef
_GNU_SOURCEso thatrseq.ccontrols whether or not it wants to build with_GNU_SOURCE.Reported-by Muhammad Usama Anjum <[email protected]>Signed-off-by Sean Christopherson <[email protected]>
Signature · 2 lines
Thanks, Oliver
Sean Christopherson
reviewerQuoted 8 lines · Sean Christopherson
Define
_GNU_SOURCEis the base CFLAGS instead of relying on selftests to manually #define_GNU_SOURCE, which is repetitive and error prone. E.g.kselftest_harness.hrequires_GNU_SOURCEforasprintf(), but if a selftest includeskvm_test_harness.hafterstdio.h, the include guards result in the effective version ofstdio.hconsumed bykvm_test_harness.hnot definingasprintf():[...]
Applied to kvm-x86 selftests_utils, thanks!
[1/1] KVM: selftest: Define _GNU_SOURCE for all selftests code
https://github.com/kvm-x86/linux/commit/730cfa45b5f4
This patch was applied to riscv/linux.git (fixes) by Sean Christopherson <[email protected]>:
Hello:
This patch was applied to riscv/linux.git (fixes)
by Sean Christopherson <[email protected]>:
Quoted 8 lines · On Tue, 23 Apr 2024 12:03:08 -0700 you wrote:
Define
_GNU_SOURCEis the base CFLAGS instead of relying on selftests to manually #define_GNU_SOURCE, which is repetitive and error prone. E.g.kselftest_harness.hrequires_GNU_SOURCEforasprintf(), but if a selftest includeskvm_test_harness.hafterstdio.h, the include guards result in the effective version ofstdio.hconsumed bykvm_test_harness.hnot definingasprintf():[...]
Here is the summary with links:
- KVM: selftest: Define _GNU_SOURCE for all selftests code
https://git.kernel.org/riscv/c/730cfa45b5f4
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html