Skip to content

Commit ef6900a

Browse files
committed
Merge tag 'trace-v5.10-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace
Pull tracing fixes from Steven Rostedt: - Use correct timestamp variable for ring buffer write stamp update - Fix up before stamp and write stamp when crossing ring buffer sub buffers - Keep a zero delta in ring buffer in slow path if cmpxchg fails - Fix trace_printk static buffer for archs that care - Fix ftrace record accounting for ftrace ops with trampolines - Fix DYNAMIC_FTRACE_WITH_DIRECT_CALLS dependency - Remove WARN_ON in hwlat tracer that triggers on something that is OK - Make "my_tramp" trampoline in ftrace direct sample code global - Fixes in the bootconfig tool for better alignment management * tag 'trace-v5.10-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace: ring-buffer: Always check to put back before stamp when crossing pages ftrace: Fix DYNAMIC_FTRACE_WITH_DIRECT_CALLS dependency ftrace: Fix updating FTRACE_FL_TRAMP tracing: Fix alignment of static buffer tracing: Remove WARN_ON in start_thread() samples/ftrace: Mark my_tramp[12]? global ring-buffer: Set the right timestamp in the slow path of __rb_reserve_next() ring-buffer: Update write stamp with the correct ts docs: bootconfig: Update file format on initrd image tools/bootconfig: Align the bootconfig applied initrd image size to 4 tools/bootconfig: Fix to check the write failure correctly tools/bootconfig: Fix errno reference after printf()
2 parents f43691b + 68e10d5 commit ef6900a

12 files changed

Lines changed: 138 additions & 62 deletions

File tree

Documentation/admin-guide/bootconfig.rst

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,15 +137,22 @@ Boot Kernel With a Boot Config
137137
==============================
138138

139139
Since the boot configuration file is loaded with initrd, it will be added
140-
to the end of the initrd (initramfs) image file with size, checksum and
141-
12-byte magic word as below.
140+
to the end of the initrd (initramfs) image file with padding, size,
141+
checksum and 12-byte magic word as below.
142142

143-
[initrd][bootconfig][size(u32)][checksum(u32)][#BOOTCONFIG\n]
143+
[initrd][bootconfig][padding][size(u32)][checksum(u32)][#BOOTCONFIG\n]
144+
145+
When the boot configuration is added to the initrd image, the total
146+
file size is aligned to 4 bytes. To fill the gap, null characters
147+
(``\0``) will be added. Thus the ``size`` is the length of the bootconfig
148+
file + padding bytes.
144149

145150
The Linux kernel decodes the last part of the initrd image in memory to
146151
get the boot configuration data.
147152
Because of this "piggyback" method, there is no need to change or
148-
update the boot loader and the kernel image itself.
153+
update the boot loader and the kernel image itself as long as the boot
154+
loader passes the correct initrd file size. If by any chance, the boot
155+
loader passes a longer size, the kernel feils to find the bootconfig data.
149156

150157
To do this operation, Linux kernel provides "bootconfig" command under
151158
tools/bootconfig, which allows admin to apply or delete the config file
@@ -176,7 +183,8 @@ up to 512 key-value pairs. If keys contains 3 words in average, it can
176183
contain 256 key-value pairs. In most cases, the number of config items
177184
will be under 100 entries and smaller than 8KB, so it would be enough.
178185
If the node number exceeds 1024, parser returns an error even if the file
179-
size is smaller than 32KB.
186+
size is smaller than 32KB. (Note that this maximum size is not including
187+
the padding null characters.)
180188
Anyway, since bootconfig command verifies it when appending a boot config
181189
to initrd image, user can notice it before boot.
182190

include/linux/bootconfig.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212

1313
#define BOOTCONFIG_MAGIC "#BOOTCONFIG\n"
1414
#define BOOTCONFIG_MAGIC_LEN 12
15+
#define BOOTCONFIG_ALIGN_SHIFT 2
16+
#define BOOTCONFIG_ALIGN (1 << BOOTCONFIG_ALIGN_SHIFT)
17+
#define BOOTCONFIG_ALIGN_MASK (BOOTCONFIG_ALIGN - 1)
1518

1619
/* XBC tree node */
1720
struct xbc_node {

kernel/trace/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ config DYNAMIC_FTRACE_WITH_REGS
202202

203203
config DYNAMIC_FTRACE_WITH_DIRECT_CALLS
204204
def_bool y
205-
depends on DYNAMIC_FTRACE
205+
depends on DYNAMIC_FTRACE_WITH_REGS
206206
depends on HAVE_DYNAMIC_FTRACE_WITH_DIRECT_CALLS
207207

208208
config FUNCTION_PROFILER

kernel/trace/ftrace.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1629,6 +1629,8 @@ static bool test_rec_ops_needs_regs(struct dyn_ftrace *rec)
16291629
static struct ftrace_ops *
16301630
ftrace_find_tramp_ops_any(struct dyn_ftrace *rec);
16311631
static struct ftrace_ops *
1632+
ftrace_find_tramp_ops_any_other(struct dyn_ftrace *rec, struct ftrace_ops *op_exclude);
1633+
static struct ftrace_ops *
16321634
ftrace_find_tramp_ops_next(struct dyn_ftrace *rec, struct ftrace_ops *ops);
16331635

16341636
static bool __ftrace_hash_rec_update(struct ftrace_ops *ops,
@@ -1778,7 +1780,7 @@ static bool __ftrace_hash_rec_update(struct ftrace_ops *ops,
17781780
* to it.
17791781
*/
17801782
if (ftrace_rec_count(rec) == 1 &&
1781-
ftrace_find_tramp_ops_any(rec))
1783+
ftrace_find_tramp_ops_any_other(rec, ops))
17821784
rec->flags |= FTRACE_FL_TRAMP;
17831785
else
17841786
rec->flags &= ~FTRACE_FL_TRAMP;
@@ -2244,6 +2246,24 @@ ftrace_find_tramp_ops_any(struct dyn_ftrace *rec)
22442246
return NULL;
22452247
}
22462248

2249+
static struct ftrace_ops *
2250+
ftrace_find_tramp_ops_any_other(struct dyn_ftrace *rec, struct ftrace_ops *op_exclude)
2251+
{
2252+
struct ftrace_ops *op;
2253+
unsigned long ip = rec->ip;
2254+
2255+
do_for_each_ftrace_op(op, ftrace_ops_list) {
2256+
2257+
if (op == op_exclude || !op->trampoline)
2258+
continue;
2259+
2260+
if (hash_contains_ip(ip, op->func_hash))
2261+
return op;
2262+
} while_for_each_ftrace_op(op);
2263+
2264+
return NULL;
2265+
}
2266+
22472267
static struct ftrace_ops *
22482268
ftrace_find_tramp_ops_next(struct dyn_ftrace *rec,
22492269
struct ftrace_ops *op)

kernel/trace/ring_buffer.c

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3234,14 +3234,12 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
32343234

32353235
/* See if we shot pass the end of this buffer page */
32363236
if (unlikely(write > BUF_PAGE_SIZE)) {
3237-
if (tail != w) {
3238-
/* before and after may now different, fix it up*/
3239-
b_ok = rb_time_read(&cpu_buffer->before_stamp, &info->before);
3240-
a_ok = rb_time_read(&cpu_buffer->write_stamp, &info->after);
3241-
if (a_ok && b_ok && info->before != info->after)
3242-
(void)rb_time_cmpxchg(&cpu_buffer->before_stamp,
3243-
info->before, info->after);
3244-
}
3237+
/* before and after may now different, fix it up*/
3238+
b_ok = rb_time_read(&cpu_buffer->before_stamp, &info->before);
3239+
a_ok = rb_time_read(&cpu_buffer->write_stamp, &info->after);
3240+
if (a_ok && b_ok && info->before != info->after)
3241+
(void)rb_time_cmpxchg(&cpu_buffer->before_stamp,
3242+
info->before, info->after);
32453243
return rb_move_tail(cpu_buffer, tail, info);
32463244
}
32473245

@@ -3287,11 +3285,11 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
32873285
ts = rb_time_stamp(cpu_buffer->buffer);
32883286
barrier();
32893287
/*E*/ if (write == (local_read(&tail_page->write) & RB_WRITE_MASK) &&
3290-
info->after < ts) {
3288+
info->after < ts &&
3289+
rb_time_cmpxchg(&cpu_buffer->write_stamp,
3290+
info->after, ts)) {
32913291
/* Nothing came after this event between C and E */
32923292
info->delta = ts - info->after;
3293-
(void)rb_time_cmpxchg(&cpu_buffer->write_stamp,
3294-
info->after, info->ts);
32953293
info->ts = ts;
32963294
} else {
32973295
/*

kernel/trace/trace.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3534,7 +3534,7 @@ __find_next_entry(struct trace_iterator *iter, int *ent_cpu,
35343534
}
35353535

35363536
#define STATIC_TEMP_BUF_SIZE 128
3537-
static char static_temp_buf[STATIC_TEMP_BUF_SIZE];
3537+
static char static_temp_buf[STATIC_TEMP_BUF_SIZE] __aligned(4);
35383538

35393539
/* Find the next real entry, without updating the iterator itself */
35403540
struct trace_entry *trace_find_next_entry(struct trace_iterator *iter,

kernel/trace/trace_hwlat.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ static int start_kthread(struct trace_array *tr)
368368
struct task_struct *kthread;
369369
int next_cpu;
370370

371-
if (WARN_ON(hwlat_kthread))
371+
if (hwlat_kthread)
372372
return 0;
373373

374374
/* Just pick the first CPU on first iteration */

samples/ftrace/ftrace-direct-modify.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ static unsigned long my_ip = (unsigned long)schedule;
2121
asm (
2222
" .pushsection .text, \"ax\", @progbits\n"
2323
" .type my_tramp1, @function\n"
24+
" .globl my_tramp1\n"
2425
" my_tramp1:"
2526
" pushq %rbp\n"
2627
" movq %rsp, %rbp\n"
@@ -29,6 +30,7 @@ asm (
2930
" .size my_tramp1, .-my_tramp1\n"
3031
" ret\n"
3132
" .type my_tramp2, @function\n"
33+
" .globl my_tramp2\n"
3234
" my_tramp2:"
3335
" pushq %rbp\n"
3436
" movq %rsp, %rbp\n"

samples/ftrace/ftrace-direct-too.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ extern void my_tramp(void *);
1616
asm (
1717
" .pushsection .text, \"ax\", @progbits\n"
1818
" .type my_tramp, @function\n"
19+
" .globl my_tramp\n"
1920
" my_tramp:"
2021
" pushq %rbp\n"
2122
" movq %rsp, %rbp\n"

samples/ftrace/ftrace-direct.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ extern void my_tramp(void *);
1414
asm (
1515
" .pushsection .text, \"ax\", @progbits\n"
1616
" .type my_tramp, @function\n"
17+
" .globl my_tramp\n"
1718
" my_tramp:"
1819
" pushq %rbp\n"
1920
" movq %rsp, %rbp\n"

0 commit comments

Comments
 (0)