Skip to content

Commit 192ffb7

Browse files
committed
Merge tag 'trace-v5.7-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace
Pull tracing fixes from Steven Rostedt: - Fix bootconfig causing kernels to fail with CONFIG_BLK_DEV_RAM enabled - Fix allocation leaks in bootconfig tool - Fix a double initialization of a variable - Fix API bootconfig usage from kprobe boot time events - Reject NULL location for kprobes - Fix crash caused by preempt delay module not cleaning up kthread correctly - Add vmalloc_sync_mappings() to prevent x86_64 page faults from recursively faulting from tracing page faults - Fix comment in gpu/trace kerneldoc header - Fix documentation of how to create a trace event class - Make the local tracing_snapshot_instance_cond() function static * tag 'trace-v5.7-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace: tools/bootconfig: Fix resource leak in apply_xbc() tracing: Make tracing_snapshot_instance_cond() static tracing: Fix doc mistakes in trace sample gpu/trace: Minor comment updates for gpu_mem_total tracepoint tracing: Add a vmalloc_sync_mappings() for safe measure tracing: Wait for preempt irq delay thread to finish tracing/kprobes: Reject new event if loc is NULL tracing/boottime: Fix kprobe event API usage tracing/kprobes: Fix a double initialization typo bootconfig: Fix to remove bootconfig data from initrd while boot
2 parents 9ecc4d7 + 8842604 commit 192ffb7

File tree

8 files changed

+114
-42
lines changed

8 files changed

+114
-42
lines changed

include/trace/events/gpu_mem.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
*
2525
* @pid: Put 0 for global total, while positive pid for process total.
2626
*
27-
* @size: Virtual size of the allocation in bytes.
27+
* @size: Size of the allocation in bytes.
2828
*
2929
*/
3030
TRACE_EVENT(gpu_mem_total,

init/main.c

Lines changed: 52 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,47 @@ static int __init loglevel(char *str)
257257

258258
early_param("loglevel", loglevel);
259259

260+
#ifdef CONFIG_BLK_DEV_INITRD
261+
static void * __init get_boot_config_from_initrd(u32 *_size, u32 *_csum)
262+
{
263+
u32 size, csum;
264+
char *data;
265+
u32 *hdr;
266+
267+
if (!initrd_end)
268+
return NULL;
269+
270+
data = (char *)initrd_end - BOOTCONFIG_MAGIC_LEN;
271+
if (memcmp(data, BOOTCONFIG_MAGIC, BOOTCONFIG_MAGIC_LEN))
272+
return NULL;
273+
274+
hdr = (u32 *)(data - 8);
275+
size = hdr[0];
276+
csum = hdr[1];
277+
278+
data = ((void *)hdr) - size;
279+
if ((unsigned long)data < initrd_start) {
280+
pr_err("bootconfig size %d is greater than initrd size %ld\n",
281+
size, initrd_end - initrd_start);
282+
return NULL;
283+
}
284+
285+
/* Remove bootconfig from initramfs/initrd */
286+
initrd_end = (unsigned long)data;
287+
if (_size)
288+
*_size = size;
289+
if (_csum)
290+
*_csum = csum;
291+
292+
return data;
293+
}
294+
#else
295+
static void * __init get_boot_config_from_initrd(u32 *_size, u32 *_csum)
296+
{
297+
return NULL;
298+
}
299+
#endif
300+
260301
#ifdef CONFIG_BOOT_CONFIG
261302

262303
char xbc_namebuf[XBC_KEYLEN_MAX] __initdata;
@@ -357,37 +398,25 @@ static void __init setup_boot_config(const char *cmdline)
357398
int pos;
358399
u32 size, csum;
359400
char *data, *copy;
360-
u32 *hdr;
361401
int ret;
362402

403+
data = get_boot_config_from_initrd(&size, &csum);
404+
if (!data)
405+
goto not_found;
406+
363407
strlcpy(tmp_cmdline, boot_command_line, COMMAND_LINE_SIZE);
364408
parse_args("bootconfig", tmp_cmdline, NULL, 0, 0, 0, NULL,
365409
bootconfig_params);
366410

367411
if (!bootconfig_found)
368412
return;
369413

370-
if (!initrd_end)
371-
goto not_found;
372-
373-
data = (char *)initrd_end - BOOTCONFIG_MAGIC_LEN;
374-
if (memcmp(data, BOOTCONFIG_MAGIC, BOOTCONFIG_MAGIC_LEN))
375-
goto not_found;
376-
377-
hdr = (u32 *)(data - 8);
378-
size = hdr[0];
379-
csum = hdr[1];
380-
381414
if (size >= XBC_DATA_MAX) {
382415
pr_err("bootconfig size %d greater than max size %d\n",
383416
size, XBC_DATA_MAX);
384417
return;
385418
}
386419

387-
data = ((void *)hdr) - size;
388-
if ((unsigned long)data < initrd_start)
389-
goto not_found;
390-
391420
if (boot_config_checksum((unsigned char *)data, size) != csum) {
392421
pr_err("bootconfig checksum failed\n");
393422
return;
@@ -420,8 +449,14 @@ static void __init setup_boot_config(const char *cmdline)
420449
not_found:
421450
pr_err("'bootconfig' found on command line, but no bootconfig found\n");
422451
}
452+
423453
#else
424-
#define setup_boot_config(cmdline) do { } while (0)
454+
455+
static void __init setup_boot_config(const char *cmdline)
456+
{
457+
/* Remove bootconfig data from initrd */
458+
get_boot_config_from_initrd(NULL, NULL);
459+
}
425460

426461
static int __init warn_bootconfig(char *str)
427462
{

kernel/trace/preemptirq_delay_test.c

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,22 +113,42 @@ static int preemptirq_delay_run(void *data)
113113

114114
for (i = 0; i < s; i++)
115115
(testfuncs[i])(i);
116+
117+
set_current_state(TASK_INTERRUPTIBLE);
118+
while (!kthread_should_stop()) {
119+
schedule();
120+
set_current_state(TASK_INTERRUPTIBLE);
121+
}
122+
123+
__set_current_state(TASK_RUNNING);
124+
116125
return 0;
117126
}
118127

119-
static struct task_struct *preemptirq_start_test(void)
128+
static int preemptirq_run_test(void)
120129
{
130+
struct task_struct *task;
131+
121132
char task_name[50];
122133

123134
snprintf(task_name, sizeof(task_name), "%s_test", test_mode);
124-
return kthread_run(preemptirq_delay_run, NULL, task_name);
135+
task = kthread_run(preemptirq_delay_run, NULL, task_name);
136+
if (IS_ERR(task))
137+
return PTR_ERR(task);
138+
if (task)
139+
kthread_stop(task);
140+
return 0;
125141
}
126142

127143

128144
static ssize_t trigger_store(struct kobject *kobj, struct kobj_attribute *attr,
129145
const char *buf, size_t count)
130146
{
131-
preemptirq_start_test();
147+
ssize_t ret;
148+
149+
ret = preemptirq_run_test();
150+
if (ret)
151+
return ret;
132152
return count;
133153
}
134154

@@ -148,11 +168,9 @@ static struct kobject *preemptirq_delay_kobj;
148168

149169
static int __init preemptirq_delay_init(void)
150170
{
151-
struct task_struct *test_task;
152171
int retval;
153172

154-
test_task = preemptirq_start_test();
155-
retval = PTR_ERR_OR_ZERO(test_task);
173+
retval = preemptirq_run_test();
156174
if (retval != 0)
157175
return retval;
158176

kernel/trace/trace.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,8 @@ int __trace_bputs(unsigned long ip, const char *str)
947947
EXPORT_SYMBOL_GPL(__trace_bputs);
948948

949949
#ifdef CONFIG_TRACER_SNAPSHOT
950-
void tracing_snapshot_instance_cond(struct trace_array *tr, void *cond_data)
950+
static void tracing_snapshot_instance_cond(struct trace_array *tr,
951+
void *cond_data)
951952
{
952953
struct tracer *tracer = tr->current_trace;
953954
unsigned long flags;
@@ -8525,6 +8526,19 @@ static int allocate_trace_buffers(struct trace_array *tr, int size)
85258526
*/
85268527
allocate_snapshot = false;
85278528
#endif
8529+
8530+
/*
8531+
* Because of some magic with the way alloc_percpu() works on
8532+
* x86_64, we need to synchronize the pgd of all the tables,
8533+
* otherwise the trace events that happen in x86_64 page fault
8534+
* handlers can't cope with accessing the chance that a
8535+
* alloc_percpu()'d memory might be touched in the page fault trace
8536+
* event. Oh, and we need to audit all other alloc_percpu() and vmalloc()
8537+
* calls in tracing, because something might get triggered within a
8538+
* page fault trace event!
8539+
*/
8540+
vmalloc_sync_mappings();
8541+
85288542
return 0;
85298543
}
85308544

kernel/trace/trace_boot.c

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -95,24 +95,20 @@ trace_boot_add_kprobe_event(struct xbc_node *node, const char *event)
9595
struct xbc_node *anode;
9696
char buf[MAX_BUF_LEN];
9797
const char *val;
98-
int ret;
98+
int ret = 0;
9999

100-
kprobe_event_cmd_init(&cmd, buf, MAX_BUF_LEN);
100+
xbc_node_for_each_array_value(node, "probes", anode, val) {
101+
kprobe_event_cmd_init(&cmd, buf, MAX_BUF_LEN);
101102

102-
ret = kprobe_event_gen_cmd_start(&cmd, event, NULL);
103-
if (ret)
104-
return ret;
103+
ret = kprobe_event_gen_cmd_start(&cmd, event, val);
104+
if (ret)
105+
break;
105106

106-
xbc_node_for_each_array_value(node, "probes", anode, val) {
107-
ret = kprobe_event_add_field(&cmd, val);
107+
ret = kprobe_event_gen_cmd_end(&cmd);
108108
if (ret)
109-
return ret;
109+
pr_err("Failed to add probe: %s\n", buf);
110110
}
111111

112-
ret = kprobe_event_gen_cmd_end(&cmd);
113-
if (ret)
114-
pr_err("Failed to add probe: %s\n", buf);
115-
116112
return ret;
117113
}
118114
#else

kernel/trace/trace_kprobe.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ static bool __within_notrace_func(unsigned long addr)
453453

454454
static bool within_notrace_func(struct trace_kprobe *tk)
455455
{
456-
unsigned long addr = addr = trace_kprobe_address(tk);
456+
unsigned long addr = trace_kprobe_address(tk);
457457
char symname[KSYM_NAME_LEN], *p;
458458

459459
if (!__within_notrace_func(addr))
@@ -940,6 +940,9 @@ EXPORT_SYMBOL_GPL(kprobe_event_cmd_init);
940940
* complete command or only the first part of it; in the latter case,
941941
* kprobe_event_add_fields() can be used to add more fields following this.
942942
*
943+
* Unlikely the synth_event_gen_cmd_start(), @loc must be specified. This
944+
* returns -EINVAL if @loc == NULL.
945+
*
943946
* Return: 0 if successful, error otherwise.
944947
*/
945948
int __kprobe_event_gen_cmd_start(struct dynevent_cmd *cmd, bool kretprobe,
@@ -953,6 +956,9 @@ int __kprobe_event_gen_cmd_start(struct dynevent_cmd *cmd, bool kretprobe,
953956
if (cmd->type != DYNEVENT_TYPE_KPROBE)
954957
return -EINVAL;
955958

959+
if (!loc)
960+
return -EINVAL;
961+
956962
if (kretprobe)
957963
snprintf(buf, MAX_EVENT_NAME_LEN, "r:kprobes/%s", name);
958964
else

samples/trace_events/trace-events-sample.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ TRACE_EVENT_FN(foo_bar_with_fn,
416416
* Note, TRACE_EVENT() itself is simply defined as:
417417
*
418418
* #define TRACE_EVENT(name, proto, args, tstruct, assign, printk) \
419-
* DEFINE_EVENT_CLASS(name, proto, args, tstruct, assign, printk); \
419+
* DECLARE_EVENT_CLASS(name, proto, args, tstruct, assign, printk); \
420420
* DEFINE_EVENT(name, name, proto, args)
421421
*
422422
* The DEFINE_EVENT() also can be declared with conditions and reg functions:

tools/bootconfig/main.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -314,31 +314,34 @@ int apply_xbc(const char *path, const char *xbc_path)
314314
ret = delete_xbc(path);
315315
if (ret < 0) {
316316
pr_err("Failed to delete previous boot config: %d\n", ret);
317+
free(data);
317318
return ret;
318319
}
319320

320321
/* Apply new one */
321322
fd = open(path, O_RDWR | O_APPEND);
322323
if (fd < 0) {
323324
pr_err("Failed to open %s: %d\n", path, fd);
325+
free(data);
324326
return fd;
325327
}
326328
/* TODO: Ensure the @path is initramfs/initrd image */
327329
ret = write(fd, data, size + 8);
328330
if (ret < 0) {
329331
pr_err("Failed to apply a boot config: %d\n", ret);
330-
return ret;
332+
goto out;
331333
}
332334
/* Write a magic word of the bootconfig */
333335
ret = write(fd, BOOTCONFIG_MAGIC, BOOTCONFIG_MAGIC_LEN);
334336
if (ret < 0) {
335337
pr_err("Failed to apply a boot config magic: %d\n", ret);
336-
return ret;
338+
goto out;
337339
}
340+
out:
338341
close(fd);
339342
free(data);
340343

341-
return 0;
344+
return ret;
342345
}
343346

344347
int usage(void)

0 commit comments

Comments
 (0)