1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2 /* 3 * Copyright (c) 2021, Microsoft Corporation. 4 * 5 * Authors: 6 * Beau Belgrave <[email protected]> 7 */ 8 #ifndef _UAPI_LINUX_USER_EVENTS_H 9 #define _UAPI_LINUX_USER_EVENTS_H 10 11 #include <linux/types.h> 12 #include <linux/ioctl.h> 13 14 #ifdef __KERNEL__ 15 #include <linux/uio.h> 16 #else 17 #include <sys/uio.h> 18 #endif 19 20 #define USER_EVENTS_SYSTEM "user_events" 21 #define USER_EVENTS_PREFIX "u:" 22 23 /* Bits 0-6 are for known probe types, Bit 7 is for unknown probes */ 24 #define EVENT_BIT_FTRACE 0 25 #define EVENT_BIT_PERF 1 26 #define EVENT_BIT_OTHER 7 27 28 #define EVENT_STATUS_FTRACE (1 << EVENT_BIT_FTRACE) 29 #define EVENT_STATUS_PERF (1 << EVENT_BIT_PERF) 30 #define EVENT_STATUS_OTHER (1 << EVENT_BIT_OTHER) 31 32 /* Create dynamic location entry within a 32-bit value */ 33 #define DYN_LOC(offset, size) ((size) << 16 | (offset)) 34 35 /* Use raw iterator for attached BPF program(s), no affect on ftrace/perf */ 36 #define FLAG_BPF_ITER (1 << 0) 37 38 /* 39 * Describes an event registration and stores the results of the registration. 40 * This structure is passed to the DIAG_IOCSREG ioctl, callers at a minimum 41 * must set the size and name_args before invocation. 42 */ 43 struct user_reg { 44 45 /* Input: Size of the user_reg structure being used */ 46 __u32 size; 47 48 /* Input: Pointer to string with event name, description and flags */ 49 __u64 name_args; 50 51 /* Output: Byte index of the event within the status page */ 52 __u32 status_index; 53 54 /* Output: Index of the event to use when writing data */ 55 __u32 write_index; 56 }; 57 58 #define DIAG_IOC_MAGIC '*' 59 60 /* Requests to register a user_event */ 61 #define DIAG_IOCSREG _IOWR(DIAG_IOC_MAGIC, 0, struct user_reg*) 62 63 /* Requests to delete a user_event */ 64 #define DIAG_IOCSDEL _IOW(DIAG_IOC_MAGIC, 1, char*) 65 66 /* Data type that was passed to the BPF program */ 67 enum { 68 /* Data resides in kernel space */ 69 USER_BPF_DATA_KERNEL, 70 71 /* Data resides in user space */ 72 USER_BPF_DATA_USER, 73 74 /* Data is a pointer to a user_bpf_iter structure */ 75 USER_BPF_DATA_ITER, 76 }; 77 78 /* 79 * Describes an iovec iterator that BPF programs can use to access data for 80 * a given user_event write() / writev() call. 81 */ 82 struct user_bpf_iter { 83 84 /* Offset of the data within the first iovec */ 85 __u32 iov_offset; 86 87 /* Number of iovec structures */ 88 __u32 nr_segs; 89 90 /* Pointer to iovec structures */ 91 const struct iovec *iov; 92 }; 93 94 /* Context that BPF programs receive when attached to a user_event */ 95 struct user_bpf_context { 96 97 /* Data type being passed (see union below) */ 98 __u32 data_type; 99 100 /* Length of the data */ 101 __u32 data_len; 102 103 /* Pointer to data, varies by data type */ 104 union { 105 /* Kernel data (data_type == USER_BPF_DATA_KERNEL) */ 106 void *kdata; 107 108 /* User data (data_type == USER_BPF_DATA_USER) */ 109 void *udata; 110 111 /* Direct iovec (data_type == USER_BPF_DATA_ITER) */ 112 struct user_bpf_iter *iter; 113 }; 114 }; 115 116 #endif /* _UAPI_LINUX_USER_EVENTS_H */ 117