Skip to content

Commit 4b6f7c6

Browse files
committed
Merge tag 'trace-v6.8-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace
Pull tracing fixes from Steven Rostedt: - Fix the #ifndef that didn't have the 'CONFIG_' prefix on HAVE_DYNAMIC_FTRACE_WITH_REGS The fix to have dynamic trampolines work with x86 broke arm64 as the config used in the #ifdef was HAVE_DYNAMIC_FTRACE_WITH_REGS and not CONFIG_HAVE_DYNAMIC_FTRACE_WITH_REGS which removed the fix that the previous fix was to fix. - Fix tracing_on state The code to test if "tracing_on" is set incorrectly used ring_buffer_record_is_on() which returns false if the ring buffer isn't able to be written to. But the ring buffer disable has several bits that disable it. One is internal disabling which is used for resizing and other modifications of the ring buffer. But the "tracing_on" user space visible flag should only report if tracing is actually on and not internally disabled, as this can cause confusion as writing "1" when it is disabled will not enable it. Instead use ring_buffer_record_is_set_on() which shows the user space visible settings. - Fix a false positive kmemleak on saved cmdlines Now that the saved_cmdlines structure is allocated via alloc_page() and not via kmalloc() it has become invisible to kmemleak. The allocation done to one of its pointers was flagged as a dangling allocation leak. Make kmemleak aware of this allocation and free. - Fix synthetic event dynamic strings An update that cleaned up the synthetic event code removed the return value of trace_string(), and had it return zero instead of the length, causing dynamic strings in the synthetic event to always have zero size. - Clean up documentation and header files for seq_buf * tag 'trace-v6.8-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace: seq_buf: Fix kernel documentation seq_buf: Don't use "proxy" headers tracing/synthetic: Fix trace_string() return value tracing: Inform kmemleak of saved_cmdlines allocation tracing: Use ring_buffer_record_is_set_on() in tracer_tracing_is_on() tracing: Fix HAVE_DYNAMIC_FTRACE_WITH_REGS ifdef
2 parents 3f3f64c + 6efe4d1 commit 4b6f7c6

File tree

5 files changed

+47
-29
lines changed

5 files changed

+47
-29
lines changed

include/linux/seq_buf.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@
22
#ifndef _LINUX_SEQ_BUF_H
33
#define _LINUX_SEQ_BUF_H
44

5-
#include <linux/fs.h>
5+
#include <linux/bug.h>
6+
#include <linux/minmax.h>
7+
#include <linux/seq_file.h>
8+
#include <linux/types.h>
69

710
/*
811
* Trace sequences are used to allow a function to call several other functions
912
* to create a string of data to use.
1013
*/
1114

1215
/**
13-
* seq_buf - seq buffer structure
16+
* struct seq_buf - seq buffer structure
1417
* @buffer: pointer to the buffer
1518
* @size: size of the buffer
1619
* @len: the amount of data inside the buffer
@@ -77,10 +80,10 @@ static inline unsigned int seq_buf_used(struct seq_buf *s)
7780
}
7881

7982
/**
80-
* seq_buf_str - get %NUL-terminated C string from seq_buf
83+
* seq_buf_str - get NUL-terminated C string from seq_buf
8184
* @s: the seq_buf handle
8285
*
83-
* This makes sure that the buffer in @s is nul terminated and
86+
* This makes sure that the buffer in @s is NUL-terminated and
8487
* safe to read as a string.
8588
*
8689
* Note, if this is called when the buffer has overflowed, then
@@ -90,7 +93,7 @@ static inline unsigned int seq_buf_used(struct seq_buf *s)
9093
* After this function is called, s->buffer is safe to use
9194
* in string operations.
9295
*
93-
* Returns @s->buf after making sure it is terminated.
96+
* Returns: @s->buf after making sure it is terminated.
9497
*/
9598
static inline const char *seq_buf_str(struct seq_buf *s)
9699
{
@@ -110,7 +113,7 @@ static inline const char *seq_buf_str(struct seq_buf *s)
110113
* @s: the seq_buf handle
111114
* @bufp: the beginning of the buffer is stored here
112115
*
113-
* Return the number of bytes available in the buffer, or zero if
116+
* Returns: the number of bytes available in the buffer, or zero if
114117
* there's no space.
115118
*/
116119
static inline size_t seq_buf_get_buf(struct seq_buf *s, char **bufp)
@@ -132,7 +135,7 @@ static inline size_t seq_buf_get_buf(struct seq_buf *s, char **bufp)
132135
* @num: the number of bytes to commit
133136
*
134137
* Commit @num bytes of data written to a buffer previously acquired
135-
* by seq_buf_get. To signal an error condition, or that the data
138+
* by seq_buf_get_buf(). To signal an error condition, or that the data
136139
* didn't fit in the available space, pass a negative @num value.
137140
*/
138141
static inline void seq_buf_commit(struct seq_buf *s, int num)

kernel/trace/ftrace.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5331,7 +5331,7 @@ static int register_ftrace_function_nolock(struct ftrace_ops *ops);
53315331
* not support ftrace_regs_caller but direct_call, use SAVE_ARGS so that it
53325332
* jumps from ftrace_caller for multiple ftrace_ops.
53335333
*/
5334-
#ifndef HAVE_DYNAMIC_FTRACE_WITH_REGS
5334+
#ifndef CONFIG_HAVE_DYNAMIC_FTRACE_WITH_REGS
53355335
#define MULTI_FLAGS (FTRACE_OPS_FL_DIRECT | FTRACE_OPS_FL_SAVE_ARGS)
53365336
#else
53375337
#define MULTI_FLAGS (FTRACE_OPS_FL_DIRECT | FTRACE_OPS_FL_SAVE_REGS)

kernel/trace/trace.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include <linux/ctype.h>
4040
#include <linux/init.h>
4141
#include <linux/panic_notifier.h>
42+
#include <linux/kmemleak.h>
4243
#include <linux/poll.h>
4344
#include <linux/nmi.h>
4445
#include <linux/fs.h>
@@ -1532,7 +1533,7 @@ void disable_trace_on_warning(void)
15321533
bool tracer_tracing_is_on(struct trace_array *tr)
15331534
{
15341535
if (tr->array_buffer.buffer)
1535-
return ring_buffer_record_is_on(tr->array_buffer.buffer);
1536+
return ring_buffer_record_is_set_on(tr->array_buffer.buffer);
15361537
return !tr->buffer_disabled;
15371538
}
15381539

@@ -2339,6 +2340,7 @@ static void free_saved_cmdlines_buffer(struct saved_cmdlines_buffer *s)
23392340
int order = get_order(sizeof(*s) + s->cmdline_num * TASK_COMM_LEN);
23402341

23412342
kfree(s->map_cmdline_to_pid);
2343+
kmemleak_free(s);
23422344
free_pages((unsigned long)s, order);
23432345
}
23442346

@@ -2358,6 +2360,7 @@ static struct saved_cmdlines_buffer *allocate_cmdlines_buffer(unsigned int val)
23582360
return NULL;
23592361

23602362
s = page_address(page);
2363+
kmemleak_alloc(s, size, 1, GFP_KERNEL);
23612364
memset(s, 0, sizeof(*s));
23622365

23632366
/* Round up to actual allocation */

kernel/trace/trace_events_synth.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,8 +441,9 @@ static unsigned int trace_string(struct synth_trace_event *entry,
441441
if (is_dynamic) {
442442
union trace_synth_field *data = &entry->fields[*n_u64];
443443

444+
len = fetch_store_strlen((unsigned long)str_val);
444445
data->as_dynamic.offset = struct_size(entry, fields, event->n_u64) + data_size;
445-
data->as_dynamic.len = fetch_store_strlen((unsigned long)str_val);
446+
data->as_dynamic.len = len;
446447

447448
ret = fetch_store_string((unsigned long)str_val, &entry->fields[*n_u64], entry);
448449

lib/seq_buf.c

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,26 @@
1313
* seq_buf_init() more than once to reset the seq_buf to start
1414
* from scratch.
1515
*/
16-
#include <linux/uaccess.h>
17-
#include <linux/seq_file.h>
16+
17+
#include <linux/bug.h>
18+
#include <linux/err.h>
19+
#include <linux/export.h>
20+
#include <linux/hex.h>
21+
#include <linux/minmax.h>
22+
#include <linux/printk.h>
1823
#include <linux/seq_buf.h>
24+
#include <linux/seq_file.h>
25+
#include <linux/sprintf.h>
26+
#include <linux/string.h>
27+
#include <linux/types.h>
28+
#include <linux/uaccess.h>
1929

2030
/**
2131
* seq_buf_can_fit - can the new data fit in the current buffer?
2232
* @s: the seq_buf descriptor
2333
* @len: The length to see if it can fit in the current buffer
2434
*
25-
* Returns true if there's enough unused space in the seq_buf buffer
35+
* Returns: true if there's enough unused space in the seq_buf buffer
2636
* to fit the amount of new data according to @len.
2737
*/
2838
static bool seq_buf_can_fit(struct seq_buf *s, size_t len)
@@ -35,7 +45,7 @@ static bool seq_buf_can_fit(struct seq_buf *s, size_t len)
3545
* @m: the seq_file descriptor that is the destination
3646
* @s: the seq_buf descriptor that is the source.
3747
*
38-
* Returns zero on success, non zero otherwise
48+
* Returns: zero on success, non-zero otherwise.
3949
*/
4050
int seq_buf_print_seq(struct seq_file *m, struct seq_buf *s)
4151
{
@@ -50,9 +60,9 @@ int seq_buf_print_seq(struct seq_file *m, struct seq_buf *s)
5060
* @fmt: printf format string
5161
* @args: va_list of arguments from a printf() type function
5262
*
53-
* Writes a vnprintf() format into the sequencce buffer.
63+
* Writes a vnprintf() format into the sequence buffer.
5464
*
55-
* Returns zero on success, -1 on overflow.
65+
* Returns: zero on success, -1 on overflow.
5666
*/
5767
int seq_buf_vprintf(struct seq_buf *s, const char *fmt, va_list args)
5868
{
@@ -78,7 +88,7 @@ int seq_buf_vprintf(struct seq_buf *s, const char *fmt, va_list args)
7888
*
7989
* Writes a printf() format into the sequence buffer.
8090
*
81-
* Returns zero on success, -1 on overflow.
91+
* Returns: zero on success, -1 on overflow.
8292
*/
8393
int seq_buf_printf(struct seq_buf *s, const char *fmt, ...)
8494
{
@@ -94,12 +104,12 @@ int seq_buf_printf(struct seq_buf *s, const char *fmt, ...)
94104
EXPORT_SYMBOL_GPL(seq_buf_printf);
95105

96106
/**
97-
* seq_buf_do_printk - printk seq_buf line by line
107+
* seq_buf_do_printk - printk() seq_buf line by line
98108
* @s: seq_buf descriptor
99109
* @lvl: printk level
100110
*
101111
* printk()-s a multi-line sequential buffer line by line. The function
102-
* makes sure that the buffer in @s is nul terminated and safe to read
112+
* makes sure that the buffer in @s is NUL-terminated and safe to read
103113
* as a string.
104114
*/
105115
void seq_buf_do_printk(struct seq_buf *s, const char *lvl)
@@ -139,7 +149,7 @@ EXPORT_SYMBOL_GPL(seq_buf_do_printk);
139149
* This function will take the format and the binary array and finish
140150
* the conversion into the ASCII string within the buffer.
141151
*
142-
* Returns zero on success, -1 on overflow.
152+
* Returns: zero on success, -1 on overflow.
143153
*/
144154
int seq_buf_bprintf(struct seq_buf *s, const char *fmt, const u32 *binary)
145155
{
@@ -167,7 +177,7 @@ int seq_buf_bprintf(struct seq_buf *s, const char *fmt, const u32 *binary)
167177
*
168178
* Copy a simple string into the sequence buffer.
169179
*
170-
* Returns zero on success, -1 on overflow
180+
* Returns: zero on success, -1 on overflow.
171181
*/
172182
int seq_buf_puts(struct seq_buf *s, const char *str)
173183
{
@@ -196,7 +206,7 @@ EXPORT_SYMBOL_GPL(seq_buf_puts);
196206
*
197207
* Copy a single character into the sequence buffer.
198208
*
199-
* Returns zero on success, -1 on overflow
209+
* Returns: zero on success, -1 on overflow.
200210
*/
201211
int seq_buf_putc(struct seq_buf *s, unsigned char c)
202212
{
@@ -212,7 +222,7 @@ int seq_buf_putc(struct seq_buf *s, unsigned char c)
212222
EXPORT_SYMBOL_GPL(seq_buf_putc);
213223

214224
/**
215-
* seq_buf_putmem - write raw data into the sequenc buffer
225+
* seq_buf_putmem - write raw data into the sequence buffer
216226
* @s: seq_buf descriptor
217227
* @mem: The raw memory to copy into the buffer
218228
* @len: The length of the raw memory to copy (in bytes)
@@ -221,7 +231,7 @@ EXPORT_SYMBOL_GPL(seq_buf_putc);
221231
* buffer and a strcpy() would not work. Using this function allows
222232
* for such cases.
223233
*
224-
* Returns zero on success, -1 on overflow
234+
* Returns: zero on success, -1 on overflow.
225235
*/
226236
int seq_buf_putmem(struct seq_buf *s, const void *mem, unsigned int len)
227237
{
@@ -249,7 +259,7 @@ int seq_buf_putmem(struct seq_buf *s, const void *mem, unsigned int len)
249259
* raw memory into the buffer it writes its ASCII representation of it
250260
* in hex characters.
251261
*
252-
* Returns zero on success, -1 on overflow
262+
* Returns: zero on success, -1 on overflow.
253263
*/
254264
int seq_buf_putmem_hex(struct seq_buf *s, const void *mem,
255265
unsigned int len)
@@ -297,7 +307,7 @@ int seq_buf_putmem_hex(struct seq_buf *s, const void *mem,
297307
*
298308
* Write a path name into the sequence buffer.
299309
*
300-
* Returns the number of written bytes on success, -1 on overflow
310+
* Returns: the number of written bytes on success, -1 on overflow.
301311
*/
302312
int seq_buf_path(struct seq_buf *s, const struct path *path, const char *esc)
303313
{
@@ -332,6 +342,7 @@ int seq_buf_path(struct seq_buf *s, const struct path *path, const char *esc)
332342
* or until it reaches the end of the content in the buffer (@s->len),
333343
* whichever comes first.
334344
*
345+
* Returns:
335346
* On success, it returns a positive number of the number of bytes
336347
* it copied.
337348
*
@@ -382,11 +393,11 @@ int seq_buf_to_user(struct seq_buf *s, char __user *ubuf, size_t start, int cnt)
382393
* linebuf size is maximal length for one line.
383394
* 32 * 3 - maximum bytes per line, each printed into 2 chars + 1 for
384395
* separating space
385-
* 2 - spaces separating hex dump and ascii representation
386-
* 32 - ascii representation
396+
* 2 - spaces separating hex dump and ASCII representation
397+
* 32 - ASCII representation
387398
* 1 - terminating '\0'
388399
*
389-
* Returns zero on success, -1 on overflow
400+
* Returns: zero on success, -1 on overflow.
390401
*/
391402
int seq_buf_hex_dump(struct seq_buf *s, const char *prefix_str, int prefix_type,
392403
int rowsize, int groupsize,

0 commit comments

Comments
 (0)