KVM: selftests: Rip out old, param-based guest assert macros
authorSean Christopherson <seanjc@google.com>
Sat, 29 Jul 2023 00:36:41 +0000 (17:36 -0700)
committerSean Christopherson <seanjc@google.com>
Wed, 2 Aug 2023 21:43:16 +0000 (14:43 -0700)
Drop the param-based guest assert macros and enable the printf versions
for all selftests.  Note!  This change can affect tests even if they
don't use directly use guest asserts!  E.g. via library code, or due to
the compiler making different optimization decisions.

Link: https://lore.kernel.org/r/20230729003643.1053367-33-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
24 files changed:
tools/testing/selftests/kvm/aarch64/arch_timer.c
tools/testing/selftests/kvm/aarch64/debug-exceptions.c
tools/testing/selftests/kvm/aarch64/hypercalls.c
tools/testing/selftests/kvm/aarch64/page_fault_test.c
tools/testing/selftests/kvm/aarch64/vgic_irq.c
tools/testing/selftests/kvm/guest_print_test.c
tools/testing/selftests/kvm/include/ucall_common.h
tools/testing/selftests/kvm/memslot_perf_test.c
tools/testing/selftests/kvm/s390x/memop.c
tools/testing/selftests/kvm/s390x/tprot.c
tools/testing/selftests/kvm/set_memory_region_test.c
tools/testing/selftests/kvm/steal_time.c
tools/testing/selftests/kvm/x86_64/cpuid_test.c
tools/testing/selftests/kvm/x86_64/hyperv_extended_hypercalls.c
tools/testing/selftests/kvm/x86_64/hyperv_features.c
tools/testing/selftests/kvm/x86_64/kvm_pv_test.c
tools/testing/selftests/kvm/x86_64/monitor_mwait_test.c
tools/testing/selftests/kvm/x86_64/nested_exceptions_test.c
tools/testing/selftests/kvm/x86_64/set_boot_cpu_id.c
tools/testing/selftests/kvm/x86_64/svm_nested_soft_inject_test.c
tools/testing/selftests/kvm/x86_64/tsc_msrs_test.c
tools/testing/selftests/kvm/x86_64/userspace_io_test.c
tools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c
tools/testing/selftests/kvm/x86_64/xcr0_cpuid_test.c

index b53bcf1..274b846 100644 (file)
@@ -19,8 +19,6 @@
  *
  * Copyright (c) 2021, Google LLC.
  */
-#define USE_GUEST_ASSERT_PRINTF 1
-
 #define _GNU_SOURCE
 
 #include <stdlib.h>
index fdd5b05..f5b6cb3 100644 (file)
@@ -1,6 +1,4 @@
 // SPDX-License-Identifier: GPL-2.0
-#define USE_GUEST_ASSERT_PRINTF 1
-
 #include <test_util.h>
 #include <kvm_util.h>
 #include <processor.h>
index 94555a7..31f66ba 100644 (file)
@@ -8,8 +8,6 @@
  * hypercalls are properly masked or unmasked to the guest when disabled or
  * enabled from the KVM userspace, respectively.
  */
-#define USE_GUEST_ASSERT_PRINTF 1
-
 #include <errno.h>
 #include <linux/arm-smccc.h>
 #include <asm/kvm.h>
index 0b0dd90..47bb914 100644 (file)
@@ -7,8 +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 USE_GUEST_ASSERT_PRINTF 1
-
 #define _GNU_SOURCE
 #include <linux/bitmap.h>
 #include <fcntl.h>
index 67da33a..2e64b48 100644 (file)
@@ -7,8 +7,6 @@
  * host to inject a specific intid via a GUEST_SYNC call, and then checks that
  * it received it.
  */
-#define USE_GUEST_ASSERT_PRINTF 1
-
 #include <asm/kvm.h>
 #include <asm/kvm_para.h>
 #include <sys/eventfd.h>
index 267e01d..41230b7 100644 (file)
@@ -4,8 +4,6 @@
  *
  * Copyright 2022, Google, Inc. and/or its affiliates.
  */
-#define USE_GUEST_ASSERT_PRINTF 1
-
 #include <fcntl.h>
 #include <stdio.h>
 #include <stdlib.h>
index 9e5948d..99bbb56 100644 (file)
@@ -66,7 +66,6 @@ enum guest_assert_builtin_args {
        GUEST_ASSERT_BUILTIN_NARGS
 };
 
-#ifdef USE_GUEST_ASSERT_PRINTF
 #define ____GUEST_ASSERT(_condition, _exp, _fmt, _args...)                             \
 do {                                                                                   \
        if (!(_condition))                                                              \
@@ -108,74 +107,4 @@ do {                                                                               \
 #define GUEST_ASSERT_1(_condition, arg1) \
        __GUEST_ASSERT(_condition, "arg1 = 0x%lx", arg1)
 
-#else
-
-#define __GUEST_ASSERT(_condition, _condstr, _nargs, _args...)         \
-do {                                                                   \
-       if (!(_condition))                                              \
-               ucall(UCALL_ABORT, GUEST_ASSERT_BUILTIN_NARGS + _nargs, \
-                     "Failed guest assert: " _condstr,                 \
-                     __FILE__, __LINE__, ##_args);                     \
-} while (0)
-
-#define GUEST_ASSERT(_condition) \
-       __GUEST_ASSERT(_condition, #_condition, 0, 0)
-
-#define GUEST_ASSERT_1(_condition, arg1) \
-       __GUEST_ASSERT(_condition, #_condition, 1, (arg1))
-
-#define GUEST_ASSERT_2(_condition, arg1, arg2) \
-       __GUEST_ASSERT(_condition, #_condition, 2, (arg1), (arg2))
-
-#define GUEST_ASSERT_3(_condition, arg1, arg2, arg3) \
-       __GUEST_ASSERT(_condition, #_condition, 3, (arg1), (arg2), (arg3))
-
-#define GUEST_ASSERT_4(_condition, arg1, arg2, arg3, arg4) \
-       __GUEST_ASSERT(_condition, #_condition, 4, (arg1), (arg2), (arg3), (arg4))
-
-#define GUEST_ASSERT_EQ(a, b) __GUEST_ASSERT((a) == (b), #a " == " #b, 2, a, b)
-
-#define __REPORT_GUEST_ASSERT(_ucall, fmt, _args...)                   \
-       TEST_FAIL("%s at %s:%ld\n" fmt,                                 \
-                 (const char *)(_ucall).args[GUEST_ERROR_STRING],      \
-                 (const char *)(_ucall).args[GUEST_FILE],              \
-                 (_ucall).args[GUEST_LINE],                            \
-                 ##_args)
-
-#define GUEST_ASSERT_ARG(ucall, i) ((ucall).args[GUEST_ASSERT_BUILTIN_NARGS + i])
-
-#define REPORT_GUEST_ASSERT(ucall)             \
-       __REPORT_GUEST_ASSERT((ucall), "")
-
-#define REPORT_GUEST_ASSERT_1(ucall, fmt)                      \
-       __REPORT_GUEST_ASSERT((ucall),                          \
-                             fmt,                              \
-                             GUEST_ASSERT_ARG((ucall), 0))
-
-#define REPORT_GUEST_ASSERT_2(ucall, fmt)                      \
-       __REPORT_GUEST_ASSERT((ucall),                          \
-                             fmt,                              \
-                             GUEST_ASSERT_ARG((ucall), 0),     \
-                             GUEST_ASSERT_ARG((ucall), 1))
-
-#define REPORT_GUEST_ASSERT_3(ucall, fmt)                      \
-       __REPORT_GUEST_ASSERT((ucall),                          \
-                             fmt,                              \
-                             GUEST_ASSERT_ARG((ucall), 0),     \
-                             GUEST_ASSERT_ARG((ucall), 1),     \
-                             GUEST_ASSERT_ARG((ucall), 2))
-
-#define REPORT_GUEST_ASSERT_4(ucall, fmt)                      \
-       __REPORT_GUEST_ASSERT((ucall),                          \
-                             fmt,                              \
-                             GUEST_ASSERT_ARG((ucall), 0),     \
-                             GUEST_ASSERT_ARG((ucall), 1),     \
-                             GUEST_ASSERT_ARG((ucall), 2),     \
-                             GUEST_ASSERT_ARG((ucall), 3))
-
-#define REPORT_GUEST_ASSERT_N(ucall, fmt, args...)     \
-       __REPORT_GUEST_ASSERT((ucall), fmt, ##args)
-
-#endif /* USE_GUEST_ASSERT_PRINTF */
-
 #endif /* SELFTEST_KVM_UCALL_COMMON_H */
index 55f1bc7..20eb2e7 100644 (file)
@@ -6,8 +6,6 @@
  *
  * Basic guest setup / host vCPU thread code lifted from set_memory_region_test.
  */
-#define USE_GUEST_ASSERT_PRINTF 1
-
 #include <pthread.h>
 #include <sched.h>
 #include <semaphore.h>
index a491739..bb3ca9a 100644 (file)
@@ -4,8 +4,6 @@
  *
  * Copyright (C) 2019, Red Hat, Inc.
  */
-#define USE_GUEST_ASSERT_PRINTF 1
-
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
index c12c682..c73f948 100644 (file)
@@ -4,8 +4,6 @@
  *
  * Copyright IBM Corp. 2021
  */
-#define USE_GUEST_ASSERT_PRINTF 1
-
 #include <sys/mman.h>
 #include "test_util.h"
 #include "kvm_util.h"
index dd8f4ba..b329601 100644 (file)
@@ -1,6 +1,4 @@
 // SPDX-License-Identifier: GPL-2.0
-#define USE_GUEST_ASSERT_PRINTF 1
-
 #define _GNU_SOURCE /* for program_invocation_short_name */
 #include <fcntl.h>
 #include <pthread.h>
index 8649c85..171adfb 100644 (file)
@@ -4,8 +4,6 @@
  *
  * Copyright (C) 2020, Red Hat, Inc.
  */
-#define USE_GUEST_ASSERT_PRINTF 1
-
 #define _GNU_SOURCE
 #include <stdio.h>
 #include <time.h>
index eb1b65f..3b34d81 100644 (file)
@@ -4,8 +4,6 @@
  *
  * Generic tests for KVM CPUID set/get ioctls
  */
-#define USE_GUEST_ASSERT_PRINTF 1
-
 #include <asm/kvm_para.h>
 #include <linux/kvm_para.h>
 #include <stdint.h>
index 0107d54..e036db1 100644 (file)
@@ -8,8 +8,6 @@
  * Copyright 2022 Google LLC
  * Author: Vipin Sharma <vipinsh@google.com>
  */
-#define USE_GUEST_ASSERT_PRINTF 1
-
 #include "kvm_util.h"
 #include "processor.h"
 #include "hyperv.h"
index 41a6bef..9f28aa2 100644 (file)
@@ -4,8 +4,6 @@
  *
  * Tests for Hyper-V features enablement
  */
-#define USE_GUEST_ASSERT_PRINTF 1
-
 #include <asm/kvm_para.h>
 #include <linux/kvm_para.h>
 #include <stdint.h>
index 1c28b77..9e2879a 100644 (file)
@@ -4,8 +4,6 @@
  *
  * Tests for KVM paravirtual feature disablement
  */
-#define USE_GUEST_ASSERT_PRINTF 1
-
 #include <asm/kvm_para.h>
 #include <linux/kvm_para.h>
 #include <stdint.h>
index 960feca..80aa3d8 100644 (file)
@@ -1,6 +1,4 @@
 // SPDX-License-Identifier: GPL-2.0
-#define USE_GUEST_ASSERT_PRINTF 1
-
 #include <fcntl.h>
 #include <stdio.h>
 #include <stdlib.h>
index 4a29f59..3670331 100644 (file)
@@ -1,6 +1,4 @@
 // SPDX-License-Identifier: GPL-2.0-only
-#define USE_GUEST_ASSERT_PRINTF 1
-
 #define _GNU_SOURCE /* for program_invocation_short_name */
 
 #include "test_util.h"
index abb3f26..366cf18 100644 (file)
@@ -4,8 +4,6 @@
  *
  * Copyright (C) 2020, Red Hat, Inc.
  */
-#define USE_GUEST_ASSERT_PRINTF 1
-
 #define _GNU_SOURCE /* for program_invocation_name */
 #include <fcntl.h>
 #include <stdio.h>
index c908412..7ee4449 100644 (file)
@@ -8,8 +8,6 @@
  *   Copyright (C) 2021, Red Hat, Inc.
  *
  */
-#define USE_GUEST_ASSERT_PRINTF 1
-
 #include <stdatomic.h>
 #include <stdio.h>
 #include <unistd.h>
index cf9114f..12b0964 100644 (file)
@@ -4,8 +4,6 @@
  *
  * Copyright (C) 2020, Red Hat, Inc.
  */
-#define USE_GUEST_ASSERT_PRINTF 1
-
 #include <stdio.h>
 #include <string.h>
 #include "kvm_util.h"
index 2c5d2a1..255c50b 100644 (file)
@@ -1,6 +1,4 @@
 // SPDX-License-Identifier: GPL-2.0
-#define USE_GUEST_ASSERT_PRINTF 1
-
 #include <fcntl.h>
 #include <stdio.h>
 #include <stdlib.h>
index ba09d5a..ebbcb0a 100644 (file)
@@ -10,8 +10,6 @@
  * and check it can be retrieved with KVM_GET_MSR, also test
  * the invalid LBR formats are rejected.
  */
-#define USE_GUEST_ASSERT_PRINTF 1
-
 #define _GNU_SOURCE /* for program_invocation_short_name */
 #include <sys/ioctl.h>
 
index 5e82907..77d04a7 100644 (file)
@@ -4,8 +4,6 @@
  *
  * Copyright (C) 2022, Google LLC.
  */
-#define USE_GUEST_ASSERT_PRINTF 1
-
 #include <fcntl.h>
 #include <stdio.h>
 #include <stdlib.h>