Skip to content

Commit 61a7595

Browse files
committed
Merge tag 'trace-v5.6-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace
Pull tracing fixes from Steven Rostedt: "Various fixes: - Fix an uninitialized variable - Fix compile bug to bootconfig userspace tool (in tools directory) - Suppress some error messages of bootconfig userspace tool - Remove unneded CONFIG_LIBXBC from bootconfig - Allocate bootconfig xbc_nodes dynamically. To ease complaints about taking up static memory at boot up - Use of parse_args() to parse bootconfig instead of strstr() usage Prevents issues of double quotes containing the interested string - Fix missing ring_buffer_nest_end() on synthetic event error path - Return zero not -EINVAL on soft disabled synthetic event (soft disabling must be the same as hard disabling, which returns zero) - Consolidate synthetic event code (remove duplicate code)" * tag 'trace-v5.6-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace: tracing: Consolidate trace() functions tracing: Don't return -EINVAL when tracing soft disabled synth events tracing: Add missing nest end to synth_event_trace_start() error case tools/bootconfig: Suppress non-error messages bootconfig: Allocate xbc_nodes array dynamically bootconfig: Use parse_args() to find bootconfig and '--' tracing/kprobe: Fix uninitialized variable bug bootconfig: Remove unneeded CONFIG_LIBXBC tools/bootconfig: Fix wrong __VA_ARGS__ usage
2 parents 0a679e1 + 7276531 commit 61a7595

File tree

12 files changed

+167
-173
lines changed

12 files changed

+167
-173
lines changed

include/linux/trace_events.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ struct synth_event_trace_state {
440440
struct synth_event *event;
441441
unsigned int cur_field;
442442
unsigned int n_u64;
443-
bool enabled;
443+
bool disabled;
444444
bool add_next;
445445
bool add_name;
446446
};

init/Kconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1227,7 +1227,6 @@ endif
12271227
config BOOT_CONFIG
12281228
bool "Boot config support"
12291229
depends on BLK_DEV_INITRD
1230-
select LIBXBC
12311230
default y
12321231
help
12331232
Extra boot config allows system admin to pass a config file as

init/main.c

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,15 @@ static char *extra_command_line;
142142
/* Extra init arguments */
143143
static char *extra_init_args;
144144

145+
#ifdef CONFIG_BOOT_CONFIG
146+
/* Is bootconfig on command line? */
147+
static bool bootconfig_found;
148+
static bool initargs_found;
149+
#else
150+
# define bootconfig_found false
151+
# define initargs_found false
152+
#endif
153+
145154
static char *execute_command;
146155
static char *ramdisk_execute_command;
147156

@@ -336,17 +345,30 @@ u32 boot_config_checksum(unsigned char *p, u32 size)
336345
return ret;
337346
}
338347

348+
static int __init bootconfig_params(char *param, char *val,
349+
const char *unused, void *arg)
350+
{
351+
if (strcmp(param, "bootconfig") == 0) {
352+
bootconfig_found = true;
353+
} else if (strcmp(param, "--") == 0) {
354+
initargs_found = true;
355+
}
356+
return 0;
357+
}
358+
339359
static void __init setup_boot_config(const char *cmdline)
340360
{
361+
static char tmp_cmdline[COMMAND_LINE_SIZE] __initdata;
341362
u32 size, csum;
342363
char *data, *copy;
343-
const char *p;
344364
u32 *hdr;
345365
int ret;
346366

347-
p = strstr(cmdline, "bootconfig");
348-
if (!p || (p != cmdline && !isspace(*(p-1))) ||
349-
(p[10] && !isspace(p[10])))
367+
strlcpy(tmp_cmdline, boot_command_line, COMMAND_LINE_SIZE);
368+
parse_args("bootconfig", tmp_cmdline, NULL, 0, 0, 0, NULL,
369+
bootconfig_params);
370+
371+
if (!bootconfig_found)
350372
return;
351373

352374
if (!initrd_end)
@@ -562,11 +584,12 @@ static void __init setup_command_line(char *command_line)
562584
* to init.
563585
*/
564586
len = strlen(saved_command_line);
565-
if (!strstr(boot_command_line, " -- ")) {
587+
if (initargs_found) {
588+
saved_command_line[len++] = ' ';
589+
} else {
566590
strcpy(saved_command_line + len, " -- ");
567591
len += 4;
568-
} else
569-
saved_command_line[len++] = ' ';
592+
}
570593

571594
strcpy(saved_command_line + len, extra_init_args);
572595
}

kernel/trace/trace_events_hist.c

Lines changed: 86 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -1798,6 +1798,60 @@ void synth_event_cmd_init(struct dynevent_cmd *cmd, char *buf, int maxlen)
17981798
}
17991799
EXPORT_SYMBOL_GPL(synth_event_cmd_init);
18001800

1801+
static inline int
1802+
__synth_event_trace_start(struct trace_event_file *file,
1803+
struct synth_event_trace_state *trace_state)
1804+
{
1805+
int entry_size, fields_size = 0;
1806+
int ret = 0;
1807+
1808+
/*
1809+
* Normal event tracing doesn't get called at all unless the
1810+
* ENABLED bit is set (which attaches the probe thus allowing
1811+
* this code to be called, etc). Because this is called
1812+
* directly by the user, we don't have that but we still need
1813+
* to honor not logging when disabled. For the the iterated
1814+
* trace case, we save the enabed state upon start and just
1815+
* ignore the following data calls.
1816+
*/
1817+
if (!(file->flags & EVENT_FILE_FL_ENABLED) ||
1818+
trace_trigger_soft_disabled(file)) {
1819+
trace_state->disabled = true;
1820+
ret = -ENOENT;
1821+
goto out;
1822+
}
1823+
1824+
trace_state->event = file->event_call->data;
1825+
1826+
fields_size = trace_state->event->n_u64 * sizeof(u64);
1827+
1828+
/*
1829+
* Avoid ring buffer recursion detection, as this event
1830+
* is being performed within another event.
1831+
*/
1832+
trace_state->buffer = file->tr->array_buffer.buffer;
1833+
ring_buffer_nest_start(trace_state->buffer);
1834+
1835+
entry_size = sizeof(*trace_state->entry) + fields_size;
1836+
trace_state->entry = trace_event_buffer_reserve(&trace_state->fbuffer,
1837+
file,
1838+
entry_size);
1839+
if (!trace_state->entry) {
1840+
ring_buffer_nest_end(trace_state->buffer);
1841+
ret = -EINVAL;
1842+
}
1843+
out:
1844+
return ret;
1845+
}
1846+
1847+
static inline void
1848+
__synth_event_trace_end(struct synth_event_trace_state *trace_state)
1849+
{
1850+
trace_event_buffer_commit(&trace_state->fbuffer);
1851+
1852+
ring_buffer_nest_end(trace_state->buffer);
1853+
}
1854+
18011855
/**
18021856
* synth_event_trace - Trace a synthetic event
18031857
* @file: The trace_event_file representing the synthetic event
@@ -1819,71 +1873,38 @@ EXPORT_SYMBOL_GPL(synth_event_cmd_init);
18191873
*/
18201874
int synth_event_trace(struct trace_event_file *file, unsigned int n_vals, ...)
18211875
{
1822-
struct trace_event_buffer fbuffer;
1823-
struct synth_trace_event *entry;
1824-
struct trace_buffer *buffer;
1825-
struct synth_event *event;
1876+
struct synth_event_trace_state state;
18261877
unsigned int i, n_u64;
1827-
int fields_size = 0;
18281878
va_list args;
1829-
int ret = 0;
1830-
1831-
/*
1832-
* Normal event generation doesn't get called at all unless
1833-
* the ENABLED bit is set (which attaches the probe thus
1834-
* allowing this code to be called, etc). Because this is
1835-
* called directly by the user, we don't have that but we
1836-
* still need to honor not logging when disabled.
1837-
*/
1838-
if (!(file->flags & EVENT_FILE_FL_ENABLED))
1839-
return 0;
1840-
1841-
event = file->event_call->data;
1842-
1843-
if (n_vals != event->n_fields)
1844-
return -EINVAL;
1845-
1846-
if (trace_trigger_soft_disabled(file))
1847-
return -EINVAL;
1848-
1849-
fields_size = event->n_u64 * sizeof(u64);
1850-
1851-
/*
1852-
* Avoid ring buffer recursion detection, as this event
1853-
* is being performed within another event.
1854-
*/
1855-
buffer = file->tr->array_buffer.buffer;
1856-
ring_buffer_nest_start(buffer);
1879+
int ret;
18571880

1858-
entry = trace_event_buffer_reserve(&fbuffer, file,
1859-
sizeof(*entry) + fields_size);
1860-
if (!entry) {
1861-
ret = -EINVAL;
1862-
goto out;
1881+
ret = __synth_event_trace_start(file, &state);
1882+
if (ret) {
1883+
if (ret == -ENOENT)
1884+
ret = 0; /* just disabled, not really an error */
1885+
return ret;
18631886
}
18641887

18651888
va_start(args, n_vals);
1866-
for (i = 0, n_u64 = 0; i < event->n_fields; i++) {
1889+
for (i = 0, n_u64 = 0; i < state.event->n_fields; i++) {
18671890
u64 val;
18681891

18691892
val = va_arg(args, u64);
18701893

1871-
if (event->fields[i]->is_string) {
1894+
if (state.event->fields[i]->is_string) {
18721895
char *str_val = (char *)(long)val;
1873-
char *str_field = (char *)&entry->fields[n_u64];
1896+
char *str_field = (char *)&state.entry->fields[n_u64];
18741897

18751898
strscpy(str_field, str_val, STR_VAR_LEN_MAX);
18761899
n_u64 += STR_VAR_LEN_MAX / sizeof(u64);
18771900
} else {
1878-
entry->fields[n_u64] = val;
1901+
state.entry->fields[n_u64] = val;
18791902
n_u64++;
18801903
}
18811904
}
18821905
va_end(args);
18831906

1884-
trace_event_buffer_commit(&fbuffer);
1885-
out:
1886-
ring_buffer_nest_end(buffer);
1907+
__synth_event_trace_end(&state);
18871908

18881909
return ret;
18891910
}
@@ -1910,64 +1931,31 @@ EXPORT_SYMBOL_GPL(synth_event_trace);
19101931
int synth_event_trace_array(struct trace_event_file *file, u64 *vals,
19111932
unsigned int n_vals)
19121933
{
1913-
struct trace_event_buffer fbuffer;
1914-
struct synth_trace_event *entry;
1915-
struct trace_buffer *buffer;
1916-
struct synth_event *event;
1934+
struct synth_event_trace_state state;
19171935
unsigned int i, n_u64;
1918-
int fields_size = 0;
1919-
int ret = 0;
1920-
1921-
/*
1922-
* Normal event generation doesn't get called at all unless
1923-
* the ENABLED bit is set (which attaches the probe thus
1924-
* allowing this code to be called, etc). Because this is
1925-
* called directly by the user, we don't have that but we
1926-
* still need to honor not logging when disabled.
1927-
*/
1928-
if (!(file->flags & EVENT_FILE_FL_ENABLED))
1929-
return 0;
1930-
1931-
event = file->event_call->data;
1932-
1933-
if (n_vals != event->n_fields)
1934-
return -EINVAL;
1935-
1936-
if (trace_trigger_soft_disabled(file))
1937-
return -EINVAL;
1938-
1939-
fields_size = event->n_u64 * sizeof(u64);
1940-
1941-
/*
1942-
* Avoid ring buffer recursion detection, as this event
1943-
* is being performed within another event.
1944-
*/
1945-
buffer = file->tr->array_buffer.buffer;
1946-
ring_buffer_nest_start(buffer);
1936+
int ret;
19471937

1948-
entry = trace_event_buffer_reserve(&fbuffer, file,
1949-
sizeof(*entry) + fields_size);
1950-
if (!entry) {
1951-
ret = -EINVAL;
1952-
goto out;
1938+
ret = __synth_event_trace_start(file, &state);
1939+
if (ret) {
1940+
if (ret == -ENOENT)
1941+
ret = 0; /* just disabled, not really an error */
1942+
return ret;
19531943
}
19541944

1955-
for (i = 0, n_u64 = 0; i < event->n_fields; i++) {
1956-
if (event->fields[i]->is_string) {
1945+
for (i = 0, n_u64 = 0; i < state.event->n_fields; i++) {
1946+
if (state.event->fields[i]->is_string) {
19571947
char *str_val = (char *)(long)vals[i];
1958-
char *str_field = (char *)&entry->fields[n_u64];
1948+
char *str_field = (char *)&state.entry->fields[n_u64];
19591949

19601950
strscpy(str_field, str_val, STR_VAR_LEN_MAX);
19611951
n_u64 += STR_VAR_LEN_MAX / sizeof(u64);
19621952
} else {
1963-
entry->fields[n_u64] = vals[i];
1953+
state.entry->fields[n_u64] = vals[i];
19641954
n_u64++;
19651955
}
19661956
}
19671957

1968-
trace_event_buffer_commit(&fbuffer);
1969-
out:
1970-
ring_buffer_nest_end(buffer);
1958+
__synth_event_trace_end(&state);
19711959

19721960
return ret;
19731961
}
@@ -2004,58 +1992,17 @@ EXPORT_SYMBOL_GPL(synth_event_trace_array);
20041992
int synth_event_trace_start(struct trace_event_file *file,
20051993
struct synth_event_trace_state *trace_state)
20061994
{
2007-
struct synth_trace_event *entry;
2008-
int fields_size = 0;
2009-
int ret = 0;
1995+
int ret;
20101996

2011-
if (!trace_state) {
2012-
ret = -EINVAL;
2013-
goto out;
2014-
}
1997+
if (!trace_state)
1998+
return -EINVAL;
20151999

20162000
memset(trace_state, '\0', sizeof(*trace_state));
20172001

2018-
/*
2019-
* Normal event tracing doesn't get called at all unless the
2020-
* ENABLED bit is set (which attaches the probe thus allowing
2021-
* this code to be called, etc). Because this is called
2022-
* directly by the user, we don't have that but we still need
2023-
* to honor not logging when disabled. For the the iterated
2024-
* trace case, we save the enabed state upon start and just
2025-
* ignore the following data calls.
2026-
*/
2027-
if (!(file->flags & EVENT_FILE_FL_ENABLED)) {
2028-
trace_state->enabled = false;
2029-
goto out;
2030-
}
2031-
2032-
trace_state->enabled = true;
2033-
2034-
trace_state->event = file->event_call->data;
2035-
2036-
if (trace_trigger_soft_disabled(file)) {
2037-
ret = -EINVAL;
2038-
goto out;
2039-
}
2002+
ret = __synth_event_trace_start(file, trace_state);
2003+
if (ret == -ENOENT)
2004+
ret = 0; /* just disabled, not really an error */
20402005

2041-
fields_size = trace_state->event->n_u64 * sizeof(u64);
2042-
2043-
/*
2044-
* Avoid ring buffer recursion detection, as this event
2045-
* is being performed within another event.
2046-
*/
2047-
trace_state->buffer = file->tr->array_buffer.buffer;
2048-
ring_buffer_nest_start(trace_state->buffer);
2049-
2050-
entry = trace_event_buffer_reserve(&trace_state->fbuffer, file,
2051-
sizeof(*entry) + fields_size);
2052-
if (!entry) {
2053-
ret = -EINVAL;
2054-
goto out;
2055-
}
2056-
2057-
trace_state->entry = entry;
2058-
out:
20592006
return ret;
20602007
}
20612008
EXPORT_SYMBOL_GPL(synth_event_trace_start);
@@ -2088,7 +2035,7 @@ static int __synth_event_add_val(const char *field_name, u64 val,
20882035
trace_state->add_next = true;
20892036
}
20902037

2091-
if (!trace_state->enabled)
2038+
if (trace_state->disabled)
20922039
goto out;
20932040

20942041
event = trace_state->event;
@@ -2223,9 +2170,7 @@ int synth_event_trace_end(struct synth_event_trace_state *trace_state)
22232170
if (!trace_state)
22242171
return -EINVAL;
22252172

2226-
trace_event_buffer_commit(&trace_state->fbuffer);
2227-
2228-
ring_buffer_nest_end(trace_state->buffer);
2173+
__synth_event_trace_end(trace_state);
22292174

22302175
return 0;
22312176
}

kernel/trace/trace_kprobe.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,7 @@ int __kprobe_event_add_fields(struct dynevent_cmd *cmd, ...)
10121012
{
10131013
struct dynevent_arg arg;
10141014
va_list args;
1015-
int ret;
1015+
int ret = 0;
10161016

10171017
if (cmd->type != DYNEVENT_TYPE_KPROBE)
10181018
return -EINVAL;

0 commit comments

Comments
 (0)