^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Common code for probe-based Dynamic events.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * This code was copied from kernel/trace/trace_kprobe.c written by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Updates to make this generic:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Copyright (C) IBM Corporation, 2010-2011
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * Author: Srikar Dronamraju
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #define pr_fmt(fmt) "trace_probe: " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include "trace_probe.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #undef C
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #define C(a, b) b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) static const char *trace_probe_err_text[] = { ERRORS };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) static const char *reserved_field_names[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) "common_type",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) "common_flags",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) "common_preempt_count",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) "common_pid",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) "common_tgid",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) FIELD_STRING_IP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) FIELD_STRING_RETIP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) FIELD_STRING_FUNC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) /* Printing in basic type function template */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #define DEFINE_BASIC_PRINT_TYPE_FUNC(tname, type, fmt) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) int PRINT_TYPE_FUNC_NAME(tname)(struct trace_seq *s, void *data, void *ent)\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) trace_seq_printf(s, fmt, *(type *)data); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) return !trace_seq_has_overflowed(s); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) const char PRINT_TYPE_FMT_NAME(tname)[] = fmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) DEFINE_BASIC_PRINT_TYPE_FUNC(u8, u8, "%u")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) DEFINE_BASIC_PRINT_TYPE_FUNC(u16, u16, "%u")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) DEFINE_BASIC_PRINT_TYPE_FUNC(u32, u32, "%u")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) DEFINE_BASIC_PRINT_TYPE_FUNC(u64, u64, "%Lu")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) DEFINE_BASIC_PRINT_TYPE_FUNC(s8, s8, "%d")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) DEFINE_BASIC_PRINT_TYPE_FUNC(s16, s16, "%d")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) DEFINE_BASIC_PRINT_TYPE_FUNC(s32, s32, "%d")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) DEFINE_BASIC_PRINT_TYPE_FUNC(s64, s64, "%Ld")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) DEFINE_BASIC_PRINT_TYPE_FUNC(x8, u8, "0x%x")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) DEFINE_BASIC_PRINT_TYPE_FUNC(x16, u16, "0x%x")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) DEFINE_BASIC_PRINT_TYPE_FUNC(x32, u32, "0x%x")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) DEFINE_BASIC_PRINT_TYPE_FUNC(x64, u64, "0x%Lx")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) int PRINT_TYPE_FUNC_NAME(symbol)(struct trace_seq *s, void *data, void *ent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) trace_seq_printf(s, "%pS", (void *)*(unsigned long *)data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) return !trace_seq_has_overflowed(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) const char PRINT_TYPE_FMT_NAME(symbol)[] = "%pS";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) /* Print type function for string type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) int PRINT_TYPE_FUNC_NAME(string)(struct trace_seq *s, void *data, void *ent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) int len = *(u32 *)data >> 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) if (!len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) trace_seq_puts(s, "(fault)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) trace_seq_printf(s, "\"%s\"",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) (const char *)get_loc_data(data, ent));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) return !trace_seq_has_overflowed(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) const char PRINT_TYPE_FMT_NAME(string)[] = "\\\"%s\\\"";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) /* Fetch type information table */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) static const struct fetch_type probe_fetch_types[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) /* Special types */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) __ASSIGN_FETCH_TYPE("string", string, string, sizeof(u32), 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) "__data_loc char[]"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) __ASSIGN_FETCH_TYPE("ustring", string, string, sizeof(u32), 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) "__data_loc char[]"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) /* Basic types */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) ASSIGN_FETCH_TYPE(u8, u8, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) ASSIGN_FETCH_TYPE(u16, u16, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) ASSIGN_FETCH_TYPE(u32, u32, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) ASSIGN_FETCH_TYPE(u64, u64, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) ASSIGN_FETCH_TYPE(s8, u8, 1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) ASSIGN_FETCH_TYPE(s16, u16, 1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) ASSIGN_FETCH_TYPE(s32, u32, 1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) ASSIGN_FETCH_TYPE(s64, u64, 1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) ASSIGN_FETCH_TYPE_ALIAS(x8, u8, u8, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) ASSIGN_FETCH_TYPE_ALIAS(x16, u16, u16, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) ASSIGN_FETCH_TYPE_ALIAS(x32, u32, u32, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) ASSIGN_FETCH_TYPE_ALIAS(x64, u64, u64, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) ASSIGN_FETCH_TYPE_ALIAS(symbol, ADDR_FETCH_TYPE, ADDR_FETCH_TYPE, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) ASSIGN_FETCH_TYPE_END
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) static const struct fetch_type *find_fetch_type(const char *type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) if (!type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) type = DEFAULT_FETCH_TYPE_STR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) /* Special case: bitfield */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) if (*type == 'b') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) unsigned long bs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) type = strchr(type, '/');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) if (!type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) type++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) if (kstrtoul(type, 0, &bs))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) switch (bs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) case 8:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) return find_fetch_type("u8");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) case 16:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) return find_fetch_type("u16");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) case 32:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) return find_fetch_type("u32");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) case 64:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) return find_fetch_type("u64");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) for (i = 0; probe_fetch_types[i].name; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) if (strcmp(type, probe_fetch_types[i].name) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) return &probe_fetch_types[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) static struct trace_probe_log trace_probe_log;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) void trace_probe_log_init(const char *subsystem, int argc, const char **argv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) trace_probe_log.subsystem = subsystem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) trace_probe_log.argc = argc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) trace_probe_log.argv = argv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) trace_probe_log.index = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) void trace_probe_log_clear(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) memset(&trace_probe_log, 0, sizeof(trace_probe_log));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) void trace_probe_log_set_index(int index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) trace_probe_log.index = index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) void __trace_probe_log_err(int offset, int err_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) char *command, *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) int i, len = 0, pos = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) if (!trace_probe_log.argv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) /* Recalcurate the length and allocate buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) for (i = 0; i < trace_probe_log.argc; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) if (i == trace_probe_log.index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) pos = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) len += strlen(trace_probe_log.argv[i]) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) command = kzalloc(len, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) if (!command)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) if (trace_probe_log.index >= trace_probe_log.argc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) * Set the error position is next to the last arg + space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) * Note that len includes the terminal null and the cursor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) * appaers at pos + 1.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) pos = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) /* And make a command string from argv array */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) p = command;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) for (i = 0; i < trace_probe_log.argc; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) len = strlen(trace_probe_log.argv[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) strcpy(p, trace_probe_log.argv[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) p[len] = ' ';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) p += len + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) *(p - 1) = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) tracing_log_err(NULL, trace_probe_log.subsystem, command,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) trace_probe_err_text, err_type, pos + offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) kfree(command);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) /* Split symbol and offset. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) int traceprobe_split_symbol_offset(char *symbol, long *offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) char *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) if (!offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) tmp = strpbrk(symbol, "+-");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) if (tmp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) ret = kstrtol(tmp, 0, offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) *tmp = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) *offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) /* @buf must has MAX_EVENT_NAME_LEN size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) int traceprobe_parse_event_name(const char **pevent, const char **pgroup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) char *buf, int offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) const char *slash, *event = *pevent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) slash = strchr(event, '/');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) if (slash) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) if (slash == event) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) trace_probe_log_err(offset, NO_GROUP_NAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) if (slash - event + 1 > MAX_EVENT_NAME_LEN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) trace_probe_log_err(offset, GROUP_TOO_LONG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) strlcpy(buf, event, slash - event + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) if (!is_good_name(buf)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) trace_probe_log_err(offset, BAD_GROUP_NAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) *pgroup = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) *pevent = slash + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) offset += slash - event + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) event = *pevent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) len = strlen(event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) if (len == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) trace_probe_log_err(offset, NO_EVENT_NAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) } else if (len > MAX_EVENT_NAME_LEN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) trace_probe_log_err(offset, EVENT_TOO_LONG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) if (!is_good_name(event)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) trace_probe_log_err(offset, BAD_EVENT_NAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) #define PARAM_MAX_STACK (THREAD_SIZE / sizeof(unsigned long))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) static int parse_probe_vars(char *arg, const struct fetch_type *t,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) struct fetch_insn *code, unsigned int flags, int offs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) unsigned long param;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) if (strcmp(arg, "retval") == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) if (flags & TPARG_FL_RETURN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) code->op = FETCH_OP_RETVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) trace_probe_log_err(offs, RETVAL_ON_PROBE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) } else if ((len = str_has_prefix(arg, "stack"))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) if (arg[len] == '\0') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) code->op = FETCH_OP_STACKP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) } else if (isdigit(arg[len])) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) ret = kstrtoul(arg + len, 10, ¶m);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) goto inval_var;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) } else if ((flags & TPARG_FL_KERNEL) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) param > PARAM_MAX_STACK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) trace_probe_log_err(offs, BAD_STACK_NUM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) code->op = FETCH_OP_STACK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) code->param = (unsigned int)param;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) goto inval_var;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) } else if (strcmp(arg, "comm") == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) code->op = FETCH_OP_COMM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) #ifdef CONFIG_HAVE_FUNCTION_ARG_ACCESS_API
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) } else if (((flags & TPARG_FL_MASK) ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) (TPARG_FL_KERNEL | TPARG_FL_FENTRY)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) (len = str_has_prefix(arg, "arg"))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) ret = kstrtoul(arg + len, 10, ¶m);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) goto inval_var;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) } else if (!param || param > PARAM_MAX_STACK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) trace_probe_log_err(offs, BAD_ARG_NUM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) code->op = FETCH_OP_ARG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) code->param = (unsigned int)param - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) goto inval_var;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) inval_var:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) trace_probe_log_err(offs, BAD_VAR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) static int str_to_immediate(char *str, unsigned long *imm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) if (isdigit(str[0]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) return kstrtoul(str, 0, imm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) else if (str[0] == '-')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) return kstrtol(str, 0, (long *)imm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) else if (str[0] == '+')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) return kstrtol(str + 1, 0, (long *)imm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) static int __parse_imm_string(char *str, char **pbuf, int offs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) size_t len = strlen(str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) if (str[len - 1] != '"') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) trace_probe_log_err(offs + len, IMMSTR_NO_CLOSE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) *pbuf = kstrndup(str, len - 1, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) /* Recursive argument parser */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) parse_probe_arg(char *arg, const struct fetch_type *type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) struct fetch_insn **pcode, struct fetch_insn *end,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) unsigned int flags, int offs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) struct fetch_insn *code = *pcode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) unsigned long param;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) int deref = FETCH_OP_DEREF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) long offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) char *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) switch (arg[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) case '$':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) ret = parse_probe_vars(arg + 1, type, code, flags, offs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) case '%': /* named register */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) ret = regs_query_register_offset(arg + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) if (ret >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) code->op = FETCH_OP_REG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) code->param = (unsigned int)ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) trace_probe_log_err(offs, BAD_REG_NAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) case '@': /* memory, file-offset or symbol */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) if (isdigit(arg[1])) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) ret = kstrtoul(arg + 1, 0, ¶m);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) trace_probe_log_err(offs, BAD_MEM_ADDR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) /* load address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) code->op = FETCH_OP_IMM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) code->immediate = param;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) } else if (arg[1] == '+') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) /* kprobes don't support file offsets */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) if (flags & TPARG_FL_KERNEL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) trace_probe_log_err(offs, FILE_ON_KPROBE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) ret = kstrtol(arg + 2, 0, &offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) trace_probe_log_err(offs, BAD_FILE_OFFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) code->op = FETCH_OP_FOFFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) code->immediate = (unsigned long)offset; // imm64?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) /* uprobes don't support symbols */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) if (!(flags & TPARG_FL_KERNEL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) trace_probe_log_err(offs, SYM_ON_UPROBE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) /* Preserve symbol for updating */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) code->op = FETCH_NOP_SYMBOL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) code->data = kstrdup(arg + 1, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) if (!code->data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) if (++code == end) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) trace_probe_log_err(offs, TOO_MANY_OPS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) code->op = FETCH_OP_IMM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) code->immediate = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) /* These are fetching from memory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) if (++code == end) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) trace_probe_log_err(offs, TOO_MANY_OPS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) *pcode = code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) code->op = FETCH_OP_DEREF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) code->offset = offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) case '+': /* deref memory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) case '-':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) if (arg[1] == 'u') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) deref = FETCH_OP_UDEREF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) arg[1] = arg[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) arg++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) if (arg[0] == '+')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) arg++; /* Skip '+', because kstrtol() rejects it. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) tmp = strchr(arg, '(');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) if (!tmp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) trace_probe_log_err(offs, DEREF_NEED_BRACE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) *tmp = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) ret = kstrtol(arg, 0, &offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) trace_probe_log_err(offs, BAD_DEREF_OFFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) offs += (tmp + 1 - arg) + (arg[0] != '-' ? 1 : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) arg = tmp + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) tmp = strrchr(arg, ')');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) if (!tmp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) trace_probe_log_err(offs + strlen(arg),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) DEREF_OPEN_BRACE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) const struct fetch_type *t2 = find_fetch_type(NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) *tmp = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) ret = parse_probe_arg(arg, t2, &code, end, flags, offs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) if (code->op == FETCH_OP_COMM ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) code->op == FETCH_OP_DATA) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) trace_probe_log_err(offs, COMM_CANT_DEREF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) if (++code == end) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) trace_probe_log_err(offs, TOO_MANY_OPS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) *pcode = code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) code->op = deref;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) code->offset = offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) case '\\': /* Immediate value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) if (arg[1] == '"') { /* Immediate string */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) ret = __parse_imm_string(arg + 2, &tmp, offs + 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) code->op = FETCH_OP_DATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) code->data = tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) ret = str_to_immediate(arg + 1, &code->immediate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) trace_probe_log_err(offs + 1, BAD_IMM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) code->op = FETCH_OP_IMM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) if (!ret && code->op == FETCH_OP_NOP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) /* Parsed, but do not find fetch method */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) trace_probe_log_err(offs, BAD_FETCH_ARG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) #define BYTES_TO_BITS(nb) ((BITS_PER_LONG * (nb)) / sizeof(long))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) /* Bitfield type needs to be parsed into a fetch function */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) static int __parse_bitfield_probe_arg(const char *bf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) const struct fetch_type *t,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) struct fetch_insn **pcode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) struct fetch_insn *code = *pcode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) unsigned long bw, bo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) char *tail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) if (*bf != 'b')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) bw = simple_strtoul(bf + 1, &tail, 0); /* Use simple one */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) if (bw == 0 || *tail != '@')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) bf = tail + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) bo = simple_strtoul(bf, &tail, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) if (tail == bf || *tail != '/')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) code++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) if (code->op != FETCH_OP_NOP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) *pcode = code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) code->op = FETCH_OP_MOD_BF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) code->lshift = BYTES_TO_BITS(t->size) - (bw + bo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) code->rshift = BYTES_TO_BITS(t->size) - bw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) code->basesize = t->size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) return (BYTES_TO_BITS(t->size) < (bw + bo)) ? -EINVAL : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) /* String length checking wrapper */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) static int traceprobe_parse_probe_arg_body(char *arg, ssize_t *size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) struct probe_arg *parg, unsigned int flags, int offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) struct fetch_insn *code, *scode, *tmp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) char *t, *t2, *t3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) int ret, len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) len = strlen(arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) if (len > MAX_ARGSTR_LEN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) trace_probe_log_err(offset, ARG_TOO_LONG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) } else if (len == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) trace_probe_log_err(offset, NO_ARG_BODY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) parg->comm = kstrdup(arg, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) if (!parg->comm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) t = strchr(arg, ':');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) if (t) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) *t = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) t2 = strchr(++t, '[');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) if (t2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) *t2++ = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) t3 = strchr(t2, ']');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) if (!t3) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) offset += t2 + strlen(t2) - arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) trace_probe_log_err(offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) ARRAY_NO_CLOSE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) } else if (t3[1] != '\0') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) trace_probe_log_err(offset + t3 + 1 - arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) BAD_ARRAY_SUFFIX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) *t3 = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) if (kstrtouint(t2, 0, &parg->count) || !parg->count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) trace_probe_log_err(offset + t2 - arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) BAD_ARRAY_NUM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) if (parg->count > MAX_ARRAY_LEN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) trace_probe_log_err(offset + t2 - arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) ARRAY_TOO_BIG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) * Since $comm and immediate string can not be dereferred,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) * we can find those by strcmp.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) if (strcmp(arg, "$comm") == 0 || strncmp(arg, "\\\"", 2) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) /* The type of $comm must be "string", and not an array. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) if (parg->count || (t && strcmp(t, "string")))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) parg->type = find_fetch_type("string");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) parg->type = find_fetch_type(t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) if (!parg->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) trace_probe_log_err(offset + (t ? (t - arg) : 0), BAD_TYPE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) parg->offset = *size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) *size += parg->type->size * (parg->count ?: 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) if (parg->count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) len = strlen(parg->type->fmttype) + 6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) parg->fmt = kmalloc(len, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) if (!parg->fmt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) snprintf(parg->fmt, len, "%s[%d]", parg->type->fmttype,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) parg->count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) code = tmp = kcalloc(FETCH_INSN_MAX, sizeof(*code), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) if (!code)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) code[FETCH_INSN_MAX - 1].op = FETCH_OP_END;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) ret = parse_probe_arg(arg, parg->type, &code, &code[FETCH_INSN_MAX - 1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) flags, offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) /* Store operation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) if (!strcmp(parg->type->name, "string") ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) !strcmp(parg->type->name, "ustring")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) if (code->op != FETCH_OP_DEREF && code->op != FETCH_OP_UDEREF &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) code->op != FETCH_OP_IMM && code->op != FETCH_OP_COMM &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) code->op != FETCH_OP_DATA) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) trace_probe_log_err(offset + (t ? (t - arg) : 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) BAD_STRING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) if ((code->op == FETCH_OP_IMM || code->op == FETCH_OP_COMM ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) code->op == FETCH_OP_DATA) || parg->count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) * IMM, DATA and COMM is pointing actual address, those
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) * must be kept, and if parg->count != 0, this is an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) * array of string pointers instead of string address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) * itself.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) code++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) if (code->op != FETCH_OP_NOP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) trace_probe_log_err(offset, TOO_MANY_OPS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) /* If op == DEREF, replace it with STRING */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) if (!strcmp(parg->type->name, "ustring") ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) code->op == FETCH_OP_UDEREF)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) code->op = FETCH_OP_ST_USTRING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) code->op = FETCH_OP_ST_STRING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) code->size = parg->type->size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) parg->dynamic = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) } else if (code->op == FETCH_OP_DEREF) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) code->op = FETCH_OP_ST_MEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) code->size = parg->type->size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) } else if (code->op == FETCH_OP_UDEREF) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) code->op = FETCH_OP_ST_UMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) code->size = parg->type->size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) code++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) if (code->op != FETCH_OP_NOP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) trace_probe_log_err(offset, TOO_MANY_OPS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) code->op = FETCH_OP_ST_RAW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) code->size = parg->type->size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) scode = code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) /* Modify operation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) if (t != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) ret = __parse_bitfield_probe_arg(t, parg->type, &code);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) trace_probe_log_err(offset + t - arg, BAD_BITFIELD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) /* Loop(Array) operation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) if (parg->count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) if (scode->op != FETCH_OP_ST_MEM &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) scode->op != FETCH_OP_ST_STRING &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) scode->op != FETCH_OP_ST_USTRING) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) trace_probe_log_err(offset + (t ? (t - arg) : 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) BAD_STRING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) code++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) if (code->op != FETCH_OP_NOP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) trace_probe_log_err(offset, TOO_MANY_OPS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) code->op = FETCH_OP_LP_ARRAY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) code->param = parg->count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) code++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) code->op = FETCH_OP_END;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) /* Shrink down the code buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) parg->code = kcalloc(code - tmp + 1, sizeof(*code), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) if (!parg->code)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) memcpy(parg->code, tmp, sizeof(*code) * (code - tmp + 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) for (code = tmp; code < tmp + FETCH_INSN_MAX; code++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) if (code->op == FETCH_NOP_SYMBOL ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) code->op == FETCH_OP_DATA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) kfree(code->data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) kfree(tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) /* Return 1 if name is reserved or already used by another argument */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) static int traceprobe_conflict_field_name(const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) struct probe_arg *args, int narg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) for (i = 0; i < ARRAY_SIZE(reserved_field_names); i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) if (strcmp(reserved_field_names[i], name) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) for (i = 0; i < narg; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) if (strcmp(args[i].name, name) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) int traceprobe_parse_probe_arg(struct trace_probe *tp, int i, char *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) unsigned int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) struct probe_arg *parg = &tp->args[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) char *body;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) /* Increment count for freeing args in error case */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) tp->nr_args++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) body = strchr(arg, '=');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) if (body) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) if (body - arg > MAX_ARG_NAME_LEN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) trace_probe_log_err(0, ARG_NAME_TOO_LONG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) } else if (body == arg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) trace_probe_log_err(0, NO_ARG_NAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) parg->name = kmemdup_nul(arg, body - arg, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) body++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) /* If argument name is omitted, set "argN" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) parg->name = kasprintf(GFP_KERNEL, "arg%d", i + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) body = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) if (!parg->name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) if (!is_good_name(parg->name)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) trace_probe_log_err(0, BAD_ARG_NAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) if (traceprobe_conflict_field_name(parg->name, tp->args, i)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) trace_probe_log_err(0, USED_ARG_NAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) /* Parse fetch argument */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) return traceprobe_parse_probe_arg_body(body, &tp->size, parg, flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) body - arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) void traceprobe_free_probe_arg(struct probe_arg *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) struct fetch_insn *code = arg->code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) while (code && code->op != FETCH_OP_END) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) if (code->op == FETCH_NOP_SYMBOL ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) code->op == FETCH_OP_DATA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) kfree(code->data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) code++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) kfree(arg->code);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) kfree(arg->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) kfree(arg->comm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) kfree(arg->fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) int traceprobe_update_arg(struct probe_arg *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) struct fetch_insn *code = arg->code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) long offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) char *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) char c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) while (code && code->op != FETCH_OP_END) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) if (code->op == FETCH_NOP_SYMBOL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) if (code[1].op != FETCH_OP_IMM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) tmp = strpbrk(code->data, "+-");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) if (tmp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) c = *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) ret = traceprobe_split_symbol_offset(code->data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) &offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) code[1].immediate =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) (unsigned long)kallsyms_lookup_name(code->data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) if (tmp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) *tmp = c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) if (!code[1].immediate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) code[1].immediate += offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) code++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) /* When len=0, we just calculate the needed length */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) #define LEN_OR_ZERO (len ? len - pos : 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) static int __set_print_fmt(struct trace_probe *tp, char *buf, int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) bool is_return)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) struct probe_arg *parg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) int i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) int pos = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) const char *fmt, *arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) if (!is_return) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) fmt = "(%lx)";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) arg = "REC->" FIELD_STRING_IP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) fmt = "(%lx <- %lx)";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) arg = "REC->" FIELD_STRING_FUNC ", REC->" FIELD_STRING_RETIP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) pos += snprintf(buf + pos, LEN_OR_ZERO, "\"%s", fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) for (i = 0; i < tp->nr_args; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) parg = tp->args + i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) pos += snprintf(buf + pos, LEN_OR_ZERO, " %s=", parg->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) if (parg->count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) pos += snprintf(buf + pos, LEN_OR_ZERO, "{%s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) parg->type->fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) for (j = 1; j < parg->count; j++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) pos += snprintf(buf + pos, LEN_OR_ZERO, ",%s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) parg->type->fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) pos += snprintf(buf + pos, LEN_OR_ZERO, "}");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) pos += snprintf(buf + pos, LEN_OR_ZERO, "%s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) parg->type->fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) pos += snprintf(buf + pos, LEN_OR_ZERO, "\", %s", arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) for (i = 0; i < tp->nr_args; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) parg = tp->args + i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) if (parg->count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) if ((strcmp(parg->type->name, "string") == 0) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) (strcmp(parg->type->name, "ustring") == 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) fmt = ", __get_str(%s[%d])";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) fmt = ", REC->%s[%d]";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) for (j = 0; j < parg->count; j++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) pos += snprintf(buf + pos, LEN_OR_ZERO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) fmt, parg->name, j);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) if ((strcmp(parg->type->name, "string") == 0) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) (strcmp(parg->type->name, "ustring") == 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) fmt = ", __get_str(%s)";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) fmt = ", REC->%s";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) pos += snprintf(buf + pos, LEN_OR_ZERO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) fmt, parg->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) /* return the length of print_fmt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) return pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) #undef LEN_OR_ZERO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) int traceprobe_set_print_fmt(struct trace_probe *tp, bool is_return)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) struct trace_event_call *call = trace_probe_event_call(tp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) char *print_fmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) /* First: called with 0 length to calculate the needed length */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) len = __set_print_fmt(tp, NULL, 0, is_return);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) print_fmt = kmalloc(len + 1, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) if (!print_fmt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) /* Second: actually write the @print_fmt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) __set_print_fmt(tp, print_fmt, len + 1, is_return);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) call->print_fmt = print_fmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) int traceprobe_define_arg_fields(struct trace_event_call *event_call,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) size_t offset, struct trace_probe *tp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) int ret, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) /* Set argument names as fields */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) for (i = 0; i < tp->nr_args; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) struct probe_arg *parg = &tp->args[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) const char *fmt = parg->type->fmttype;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) int size = parg->type->size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) if (parg->fmt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) fmt = parg->fmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) if (parg->count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) size *= parg->count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) ret = trace_define_field(event_call, fmt, parg->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) offset + parg->offset, size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) parg->type->is_signed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) FILTER_OTHER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) static void trace_probe_event_free(struct trace_probe_event *tpe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) kfree(tpe->class.system);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) kfree(tpe->call.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) kfree(tpe->call.print_fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) kfree(tpe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) int trace_probe_append(struct trace_probe *tp, struct trace_probe *to)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) if (trace_probe_has_sibling(tp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) list_del_init(&tp->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) trace_probe_event_free(tp->event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) tp->event = to->event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) list_add_tail(&tp->list, trace_probe_probe_list(to));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) void trace_probe_unlink(struct trace_probe *tp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) list_del_init(&tp->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) if (list_empty(trace_probe_probe_list(tp)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) trace_probe_event_free(tp->event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) tp->event = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) void trace_probe_cleanup(struct trace_probe *tp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) for (i = 0; i < tp->nr_args; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) traceprobe_free_probe_arg(&tp->args[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) if (tp->event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) trace_probe_unlink(tp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) int trace_probe_init(struct trace_probe *tp, const char *event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) const char *group, bool alloc_filter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) struct trace_event_call *call;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) size_t size = sizeof(struct trace_probe_event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) if (!event || !group)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) if (alloc_filter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) size += sizeof(struct trace_uprobe_filter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) tp->event = kzalloc(size, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) if (!tp->event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) INIT_LIST_HEAD(&tp->event->files);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) INIT_LIST_HEAD(&tp->event->class.fields);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) INIT_LIST_HEAD(&tp->event->probes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) INIT_LIST_HEAD(&tp->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) list_add(&tp->list, &tp->event->probes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) call = trace_probe_event_call(tp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) call->class = &tp->event->class;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) call->name = kstrdup(event, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) if (!call->name) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) tp->event->class.system = kstrdup(group, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) if (!tp->event->class.system) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) trace_probe_cleanup(tp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) static struct trace_event_call *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) find_trace_event_call(const char *system, const char *event_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) struct trace_event_call *tp_event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) list_for_each_entry(tp_event, &ftrace_events, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) if (!tp_event->class->system ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) strcmp(system, tp_event->class->system))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) name = trace_event_name(tp_event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) if (!name || strcmp(event_name, name))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) return tp_event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) int trace_probe_register_event_call(struct trace_probe *tp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) struct trace_event_call *call = trace_probe_event_call(tp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) lockdep_assert_held(&event_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) if (find_trace_event_call(trace_probe_group_name(tp),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) trace_probe_name(tp)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) return -EEXIST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) ret = register_trace_event(&call->event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) ret = trace_add_event_call(call);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) unregister_trace_event(&call->event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) int trace_probe_add_file(struct trace_probe *tp, struct trace_event_file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) struct event_file_link *link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) link = kmalloc(sizeof(*link), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) if (!link)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) link->file = file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) INIT_LIST_HEAD(&link->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) list_add_tail_rcu(&link->list, &tp->event->files);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) trace_probe_set_flag(tp, TP_FLAG_TRACE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) struct event_file_link *trace_probe_get_file_link(struct trace_probe *tp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) struct trace_event_file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) struct event_file_link *link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) trace_probe_for_each_link(link, tp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) if (link->file == file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) return link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) int trace_probe_remove_file(struct trace_probe *tp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) struct trace_event_file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) struct event_file_link *link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) link = trace_probe_get_file_link(tp, file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) if (!link)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) list_del_rcu(&link->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) synchronize_rcu();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) kfree(link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) if (list_empty(&tp->event->files))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) trace_probe_clear_flag(tp, TP_FLAG_TRACE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) * Return the smallest index of different type argument (start from 1).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) * If all argument types and name are same, return 0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) int trace_probe_compare_arg_type(struct trace_probe *a, struct trace_probe *b)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) /* In case of more arguments */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) if (a->nr_args < b->nr_args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) return a->nr_args + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) if (a->nr_args > b->nr_args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) return b->nr_args + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) for (i = 0; i < a->nr_args; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) if ((b->nr_args <= i) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) ((a->args[i].type != b->args[i].type) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) (a->args[i].count != b->args[i].count) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) strcmp(a->args[i].name, b->args[i].name)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) return i + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) bool trace_probe_match_command_args(struct trace_probe *tp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) int argc, const char **argv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) char buf[MAX_ARGSTR_LEN + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) if (tp->nr_args < argc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) for (i = 0; i < argc; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) snprintf(buf, sizeof(buf), "%s=%s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) tp->args[i].name, tp->args[i].comm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) if (strcmp(buf, argv[i]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) }