~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/kvm/include/ucall_common.h

Version: ~ [ linux-6.11-rc3 ] ~ [ linux-6.10.4 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.45 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.104 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.164 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.223 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.281 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.319 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /* SPDX-License-Identifier: GPL-2.0-only */
  2 /*
  3  * Copyright (C) 2018, Google LLC.
  4  */
  5 #ifndef SELFTEST_KVM_UCALL_COMMON_H
  6 #define SELFTEST_KVM_UCALL_COMMON_H
  7 #include "test_util.h"
  8 #include "ucall.h"
  9 
 10 /* Common ucalls */
 11 enum {
 12         UCALL_NONE,
 13         UCALL_SYNC,
 14         UCALL_ABORT,
 15         UCALL_PRINTF,
 16         UCALL_DONE,
 17         UCALL_UNHANDLED,
 18 };
 19 
 20 #define UCALL_MAX_ARGS 7
 21 #define UCALL_BUFFER_LEN 1024
 22 
 23 struct ucall {
 24         uint64_t cmd;
 25         uint64_t args[UCALL_MAX_ARGS];
 26         char buffer[UCALL_BUFFER_LEN];
 27 
 28         /* Host virtual address of this struct. */
 29         struct ucall *hva;
 30 };
 31 
 32 void ucall_arch_init(struct kvm_vm *vm, vm_paddr_t mmio_gpa);
 33 void ucall_arch_do_ucall(vm_vaddr_t uc);
 34 void *ucall_arch_get_ucall(struct kvm_vcpu *vcpu);
 35 
 36 void ucall(uint64_t cmd, int nargs, ...);
 37 __printf(2, 3) void ucall_fmt(uint64_t cmd, const char *fmt, ...);
 38 __printf(5, 6) void ucall_assert(uint64_t cmd, const char *exp,
 39                                  const char *file, unsigned int line,
 40                                  const char *fmt, ...);
 41 uint64_t get_ucall(struct kvm_vcpu *vcpu, struct ucall *uc);
 42 void ucall_init(struct kvm_vm *vm, vm_paddr_t mmio_gpa);
 43 int ucall_nr_pages_required(uint64_t page_size);
 44 
 45 /*
 46  * Perform userspace call without any associated data.  This bare call avoids
 47  * allocating a ucall struct, which can be useful if the atomic operations in
 48  * the full ucall() are problematic and/or unwanted.  Note, this will come out
 49  * as UCALL_NONE on the backend.
 50  */
 51 #define GUEST_UCALL_NONE()      ucall_arch_do_ucall((vm_vaddr_t)NULL)
 52 
 53 #define GUEST_SYNC_ARGS(stage, arg1, arg2, arg3, arg4)  \
 54                                 ucall(UCALL_SYNC, 6, "hello", stage, arg1, arg2, arg3, arg4)
 55 #define GUEST_SYNC(stage)       ucall(UCALL_SYNC, 2, "hello", stage)
 56 #define GUEST_SYNC1(arg0)       ucall(UCALL_SYNC, 1, arg0)
 57 #define GUEST_SYNC2(arg0, arg1) ucall(UCALL_SYNC, 2, arg0, arg1)
 58 #define GUEST_SYNC3(arg0, arg1, arg2) \
 59                                 ucall(UCALL_SYNC, 3, arg0, arg1, arg2)
 60 #define GUEST_SYNC4(arg0, arg1, arg2, arg3) \
 61                                 ucall(UCALL_SYNC, 4, arg0, arg1, arg2, arg3)
 62 #define GUEST_SYNC5(arg0, arg1, arg2, arg3, arg4) \
 63                                 ucall(UCALL_SYNC, 5, arg0, arg1, arg2, arg3, arg4)
 64 #define GUEST_SYNC6(arg0, arg1, arg2, arg3, arg4, arg5) \
 65                                 ucall(UCALL_SYNC, 6, arg0, arg1, arg2, arg3, arg4, arg5)
 66 
 67 #define GUEST_PRINTF(_fmt, _args...) ucall_fmt(UCALL_PRINTF, _fmt, ##_args)
 68 #define GUEST_DONE()            ucall(UCALL_DONE, 0)
 69 
 70 #define REPORT_GUEST_PRINTF(ucall) pr_info("%s", (ucall).buffer)
 71 
 72 enum guest_assert_builtin_args {
 73         GUEST_ERROR_STRING,
 74         GUEST_FILE,
 75         GUEST_LINE,
 76         GUEST_ASSERT_BUILTIN_NARGS
 77 };
 78 
 79 #define ____GUEST_ASSERT(_condition, _exp, _fmt, _args...)                              \
 80 do {                                                                                    \
 81         if (!(_condition))                                                              \
 82                 ucall_assert(UCALL_ABORT, _exp, __FILE__, __LINE__, _fmt, ##_args);     \
 83 } while (0)
 84 
 85 #define __GUEST_ASSERT(_condition, _fmt, _args...)                              \
 86         ____GUEST_ASSERT(_condition, #_condition, _fmt, ##_args)
 87 
 88 #define GUEST_ASSERT(_condition)                                                \
 89         __GUEST_ASSERT(_condition, #_condition)
 90 
 91 #define GUEST_FAIL(_fmt, _args...)                                              \
 92         ucall_assert(UCALL_ABORT, "Unconditional guest failure",                \
 93                      __FILE__, __LINE__, _fmt, ##_args)
 94 
 95 #define GUEST_ASSERT_EQ(a, b)                                                   \
 96 do {                                                                            \
 97         typeof(a) __a = (a);                                                    \
 98         typeof(b) __b = (b);                                                    \
 99         ____GUEST_ASSERT(__a == __b, #a " == " #b, "%#lx != %#lx (%s != %s)",   \
100                          (unsigned long)(__a), (unsigned long)(__b), #a, #b);   \
101 } while (0)
102 
103 #define GUEST_ASSERT_NE(a, b)                                                   \
104 do {                                                                            \
105         typeof(a) __a = (a);                                                    \
106         typeof(b) __b = (b);                                                    \
107         ____GUEST_ASSERT(__a != __b, #a " != " #b, "%#lx == %#lx (%s == %s)",   \
108                          (unsigned long)(__a), (unsigned long)(__b), #a, #b);   \
109 } while (0)
110 
111 #define REPORT_GUEST_ASSERT(ucall)                                              \
112         test_assert(false, (const char *)(ucall).args[GUEST_ERROR_STRING],      \
113                     (const char *)(ucall).args[GUEST_FILE],                     \
114                     (ucall).args[GUEST_LINE], "%s", (ucall).buffer)
115 
116 #endif /* SELFTEST_KVM_UCALL_COMMON_H */
117 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php