Skip to content

Commit ab486bc

Browse files
committed
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/pmladek/printk
Pull printk updates from Petr Mladek: - Add a console_msg_format command line option: The value "default" keeps the old "[time stamp] text\n" format. The value "syslog" allows to see the syslog-like "<log level>[timestamp] text" format. This feature was requested by people doing regression tests, for example, 0day robot. They want to have both filtered and full logs at hands. - Reduce the risk of softlockup: Pass the console owner in a busy loop. This is a new approach to the old problem. It was first proposed by Steven Rostedt on Kernel Summit 2017. It marks a context in which the console_lock owner calls console drivers and could not sleep. On the other side, printk() callers could detect this state and use a busy wait instead of a simple console_trylock(). Finally, the console_lock owner checks if there is a busy waiter at the end of the special context and eventually passes the console_lock to the waiter. The hand-off works surprisingly well and helps in many situations. Well, there is still a possibility of the softlockup, for example, when the flood of messages stops and the last owner still has too much to flush. There is increasing number of people having problems with printk-related softlockups. We might eventually need to get better solution. Anyway, this looks like a good start and promising direction. - Do not allow to schedule in console_unlock() called from printk(): This reverts an older controversial commit. The reschedule helped to avoid softlockups. But it also slowed down the console output. This patch is obsoleted by the new console waiter logic described above. In fact, the reschedule made the hand-off less effective. - Deprecate "%pf" and "%pF" format specifier: It was needed on ia64, ppc64 and parisc64 to dereference function descriptors and show the real function address. It is done transparently by "%ps" and "pS" format specifier now. Sergey Senozhatsky found that all the function descriptors were in a special elf section and could be easily detected. - Remove printk_symbol() API: It has been obsoleted by "%pS" format specifier, and this change helped to remove few continuous lines and a less intuitive old API. - Remove redundant memsets: Sergey removed unnecessary memset when processing printk.devkmsg command line option. * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/pmladek/printk: (27 commits) printk: drop redundant devkmsg_log_str memsets printk: Never set console_may_schedule in console_trylock() printk: Hide console waiter logic into helpers printk: Add console owner and waiter logic to load balance console writes kallsyms: remove print_symbol() function checkpatch: add pF/pf deprecation warning symbol lookup: introduce dereference_symbol_descriptor() parisc64: Add .opd based function descriptor dereference powerpc64: Add .opd based function descriptor dereference ia64: Add .opd based function descriptor dereference sections: split dereference_function_descriptor() openrisc: Fix conflicting types for _exext and _stext lib: do not use print_symbol() irq debug: do not use print_symbol() sysfs: do not use print_symbol() drivers: do not use print_symbol() x86: do not use print_symbol() unicore32: do not use print_symbol() sh: do not use print_symbol() mn10300: do not use print_symbol() ...
2 parents 34b1cf6 + bb4f552 commit ab486bc

File tree

39 files changed

+428
-172
lines changed

39 files changed

+428
-172
lines changed

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,20 @@
646646
console=brl,ttyS0
647647
For now, only VisioBraille is supported.
648648

649+
console_msg_format=
650+
[KNL] Change console messages format
651+
default
652+
By default we print messages on consoles in
653+
"[time stamp] text\n" format (time stamp may not be
654+
printed, depending on CONFIG_PRINTK_TIME or
655+
`printk_time' param).
656+
syslog
657+
Switch to syslog format: "<%u>[time stamp] text\n"
658+
IOW, each message will have a facility and loglevel
659+
prefix. The format is similar to one used by syslog()
660+
syscall, or to executing "dmesg -S --raw" or to reading
661+
from /proc/kmsg.
662+
649663
consoleblank= [KNL] The console blank (screen saver) timeout in
650664
seconds. A value of 0 disables the blank timer.
651665
Defaults to 0.

Documentation/core-api/printk-formats.rst

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -68,42 +68,32 @@ Symbols/Function Pointers
6868

6969
::
7070

71+
%pS versatile_init+0x0/0x110
72+
%ps versatile_init
7173
%pF versatile_init+0x0/0x110
7274
%pf versatile_init
73-
%pS versatile_init+0x0/0x110
7475
%pSR versatile_init+0x9/0x110
7576
(with __builtin_extract_return_addr() translation)
76-
%ps versatile_init
7777
%pB prev_fn_of_versatile_init+0x88/0x88
7878

7979

80-
The ``F`` and ``f`` specifiers are for printing function pointers,
81-
for example, f->func, &gettimeofday. They have the same result as
82-
``S`` and ``s`` specifiers. But they do an extra conversion on
83-
ia64, ppc64 and parisc64 architectures where the function pointers
84-
are actually function descriptors.
80+
The ``S`` and ``s`` specifiers are used for printing a pointer in symbolic
81+
format. They result in the symbol name with (S) or without (s)
82+
offsets. If KALLSYMS are disabled then the symbol address is printed instead.
8583

86-
The ``S`` and ``s`` specifiers can be used for printing symbols
87-
from direct addresses, for example, __builtin_return_address(0),
88-
(void *)regs->ip. They result in the symbol name with (S) or
89-
without (s) offsets. If KALLSYMS are disabled then the symbol
90-
address is printed instead.
84+
Note, that the ``F`` and ``f`` specifiers are identical to ``S`` (``s``)
85+
and thus deprecated. We have ``F`` and ``f`` because on ia64, ppc64 and
86+
parisc64 function pointers are indirect and, in fact, are function
87+
descriptors, which require additional dereferencing before we can lookup
88+
the symbol. As of now, ``S`` and ``s`` perform dereferencing on those
89+
platforms (when needed), so ``F`` and ``f`` exist for compatibility
90+
reasons only.
9191

9292
The ``B`` specifier results in the symbol name with offsets and should be
9393
used when printing stack backtraces. The specifier takes into
9494
consideration the effect of compiler optimisations which may occur
9595
when tail-calls are used and marked with the noreturn GCC attribute.
9696

97-
Examples::
98-
99-
printk("Going to call: %pF\n", gettimeofday);
100-
printk("Going to call: %pF\n", p->func);
101-
printk("%s: called from %pS\n", __func__, (void *)_RET_IP_);
102-
printk("%s: called from %pS\n", __func__,
103-
(void *)__builtin_return_address(0));
104-
printk("Faulted at %pS\n", (void *)regs->ip);
105-
printk(" %s%pB\n", (reliable ? "" : "? "), (void *)*stack);
106-
10797
Kernel Pointers
10898
---------------
10999

Documentation/filesystems/sysfs.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ static ssize_t dev_attr_show(struct kobject *kobj, struct attribute *attr,
154154
if (dev_attr->show)
155155
ret = dev_attr->show(dev, dev_attr, buf);
156156
if (ret >= (ssize_t)PAGE_SIZE) {
157-
print_symbol("dev_attr_show: %s returned bad count\n",
158-
(unsigned long)dev_attr->show);
157+
printk("dev_attr_show: %pS returned bad count\n",
158+
dev_attr->show);
159159
}
160160
return ret;
161161
}

Documentation/translations/zh_CN/filesystems/sysfs.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ static ssize_t dev_attr_show(struct kobject *kobj, struct attribute *attr,
167167
if (dev_attr->show)
168168
ret = dev_attr->show(dev, dev_attr, buf);
169169
if (ret >= (ssize_t)PAGE_SIZE) {
170-
print_symbol("dev_attr_show: %s returned bad count\n",
171-
(unsigned long)dev_attr->show);
170+
printk("dev_attr_show: %pS returned bad count\n",
171+
dev_attr->show);
172172
}
173173
return ret;
174174
}

arch/arm/kernel/process.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include <linux/unistd.h>
2222
#include <linux/user.h>
2323
#include <linux/interrupt.h>
24-
#include <linux/kallsyms.h>
2524
#include <linux/init.h>
2625
#include <linux/elfcore.h>
2726
#include <linux/pm.h>
@@ -121,8 +120,8 @@ void __show_regs(struct pt_regs *regs)
121120

122121
show_regs_print_info(KERN_DEFAULT);
123122

124-
print_symbol("PC is at %s\n", instruction_pointer(regs));
125-
print_symbol("LR is at %s\n", regs->ARM_lr);
123+
printk("PC is at %pS\n", (void *)instruction_pointer(regs));
124+
printk("LR is at %pS\n", (void *)regs->ARM_lr);
126125
printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n",
127126
regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr);
128127
printk("sp : %08lx ip : %08lx fp : %08lx\n",

arch/arm64/kernel/process.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
#include <linux/delay.h>
3636
#include <linux/reboot.h>
3737
#include <linux/interrupt.h>
38-
#include <linux/kallsyms.h>
3938
#include <linux/init.h>
4039
#include <linux/cpu.h>
4140
#include <linux/elfcore.h>
@@ -221,8 +220,8 @@ void __show_regs(struct pt_regs *regs)
221220

222221
show_regs_print_info(KERN_DEFAULT);
223222
print_pstate(regs);
224-
print_symbol("pc : %s\n", regs->pc);
225-
print_symbol("lr : %s\n", lr);
223+
printk("pc : %pS\n", (void *)regs->pc);
224+
printk("lr : %pS\n", (void *)lr);
226225
printk("sp : %016llx\n", sp);
227226

228227
i = top_reg;

arch/c6x/kernel/traps.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include <linux/module.h>
1212
#include <linux/ptrace.h>
1313
#include <linux/sched/debug.h>
14-
#include <linux/kallsyms.h>
1514
#include <linux/bug.h>
1615

1716
#include <asm/soc.h>
@@ -375,8 +374,7 @@ static void show_trace(unsigned long *stack, unsigned long *endstack)
375374
if (i % 5 == 0)
376375
pr_debug("\n ");
377376
#endif
378-
pr_debug(" [<%08lx>]", addr);
379-
print_symbol(" %s\n", addr);
377+
pr_debug(" [<%08lx>] %pS\n", addr, (void *)addr);
380378
i++;
381379
}
382380
}

arch/ia64/include/asm/sections.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ extern char __start_gate_brl_fsys_bubble_down_patchlist[], __end_gate_brl_fsys_b
2727
extern char __start_unwind[], __end_unwind[];
2828
extern char __start_ivt_text[], __end_ivt_text[];
2929

30+
#define HAVE_DEREFERENCE_FUNCTION_DESCRIPTOR 1
31+
3032
#undef dereference_function_descriptor
3133
static inline void *dereference_function_descriptor(void *ptr)
3234
{
@@ -38,6 +40,12 @@ static inline void *dereference_function_descriptor(void *ptr)
3840
return ptr;
3941
}
4042

43+
#undef dereference_kernel_function_descriptor
44+
static inline void *dereference_kernel_function_descriptor(void *ptr)
45+
{
46+
if (ptr < (void *)__start_opd || ptr >= (void *)__end_opd)
47+
return ptr;
48+
return dereference_function_descriptor(ptr);
49+
}
4150

4251
#endif /* _ASM_IA64_SECTIONS_H */
43-

arch/ia64/kernel/module.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
#include <asm/patch.h>
3838
#include <asm/unaligned.h>
39+
#include <asm/sections.h>
3940

4041
#define ARCH_MODULE_DEBUG 0
4142

@@ -918,3 +919,14 @@ module_arch_cleanup (struct module *mod)
918919
if (mod->arch.core_unw_table)
919920
unw_remove_unwind_table(mod->arch.core_unw_table);
920921
}
922+
923+
void *dereference_module_function_descriptor(struct module *mod, void *ptr)
924+
{
925+
Elf64_Shdr *opd = mod->arch.opd;
926+
927+
if (ptr < (void *)opd->sh_addr ||
928+
ptr >= (void *)(opd->sh_addr + opd->sh_size))
929+
return ptr;
930+
931+
return dereference_function_descriptor(ptr);
932+
}

arch/ia64/kernel/process.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include <linux/pm.h>
1414
#include <linux/elf.h>
1515
#include <linux/errno.h>
16-
#include <linux/kallsyms.h>
1716
#include <linux/kernel.h>
1817
#include <linux/mm.h>
1918
#include <linux/slab.h>
@@ -69,7 +68,6 @@ void
6968
ia64_do_show_stack (struct unw_frame_info *info, void *arg)
7069
{
7170
unsigned long ip, sp, bsp;
72-
char buf[128]; /* don't make it so big that it overflows the stack! */
7371

7472
printk("\nCall Trace:\n");
7573
do {
@@ -79,11 +77,9 @@ ia64_do_show_stack (struct unw_frame_info *info, void *arg)
7977

8078
unw_get_sp(info, &sp);
8179
unw_get_bsp(info, &bsp);
82-
snprintf(buf, sizeof(buf),
83-
" [<%016lx>] %%s\n"
80+
printk(" [<%016lx>] %pS\n"
8481
" sp=%016lx bsp=%016lx\n",
85-
ip, sp, bsp);
86-
print_symbol(buf, ip);
82+
ip, (void *)ip, sp, bsp);
8783
} while (unw_unwind(info) >= 0);
8884
}
8985

@@ -111,7 +107,7 @@ show_regs (struct pt_regs *regs)
111107
printk("psr : %016lx ifs : %016lx ip : [<%016lx>] %s (%s)\n",
112108
regs->cr_ipsr, regs->cr_ifs, ip, print_tainted(),
113109
init_utsname()->release);
114-
print_symbol("ip is at %s\n", ip);
110+
printk("ip is at %pS\n", (void *)ip);
115111
printk("unat: %016lx pfs : %016lx rsc : %016lx\n",
116112
regs->ar_unat, regs->ar_pfs, regs->ar_rsc);
117113
printk("rnat: %016lx bsps: %016lx pr : %016lx\n",

arch/ia64/kernel/vmlinux.lds.S

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@ SECTIONS {
109109
RODATA
110110

111111
.opd : AT(ADDR(.opd) - LOAD_OFFSET) {
112+
__start_opd = .;
112113
*(.opd)
114+
__end_opd = .;
113115
}
114116

115117
/*

arch/mn10300/kernel/traps.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include <linux/delay.h>
2323
#include <linux/spinlock.h>
2424
#include <linux/interrupt.h>
25-
#include <linux/kallsyms.h>
2625
#include <linux/pci.h>
2726
#include <linux/kdebug.h>
2827
#include <linux/bug.h>
@@ -262,8 +261,7 @@ void show_trace(unsigned long *sp)
262261
raslot = ULONG_MAX;
263262
else
264263
printk(" ?");
265-
print_symbol(" %s", addr);
266-
printk("\n");
264+
printk(" %pS\n", (void *)addr);
267265
}
268266
}
269267

arch/openrisc/kernel/traps.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@
3939
#include <asm/io.h>
4040
#include <asm/pgtable.h>
4141
#include <asm/unwinder.h>
42-
43-
extern char _etext, _stext;
42+
#include <asm/sections.h>
4443

4544
int kstack_depth_to_print = 0x180;
4645
int lwa_flag;

arch/parisc/boot/compressed/vmlinux.lds.S

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ SECTIONS
2929
. = ALIGN(16);
3030
/* Linkage tables */
3131
.opd : {
32+
__start_opd = .;
3233
*(.opd)
34+
__end_opd = .;
3335
} PROVIDE (__gp = .);
3436
.plt : {
3537
*(.plt)

arch/parisc/include/asm/sections.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,14 @@
66
#include <asm-generic/sections.h>
77

88
#ifdef CONFIG_64BIT
9+
10+
#define HAVE_DEREFERENCE_FUNCTION_DESCRIPTOR 1
11+
912
#undef dereference_function_descriptor
1013
void *dereference_function_descriptor(void *);
14+
15+
#undef dereference_kernel_function_descriptor
16+
void *dereference_kernel_function_descriptor(void *);
1117
#endif
1218

1319
#endif

arch/parisc/kernel/module.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666

6767
#include <asm/pgtable.h>
6868
#include <asm/unwind.h>
69+
#include <asm/sections.h>
6970

7071
#if 0
7172
#define DEBUGP printk
@@ -954,3 +955,18 @@ void module_arch_cleanup(struct module *mod)
954955
{
955956
deregister_unwind_table(mod);
956957
}
958+
959+
#ifdef CONFIG_64BIT
960+
void *dereference_module_function_descriptor(struct module *mod, void *ptr)
961+
{
962+
unsigned long start_opd = (Elf64_Addr)mod->core_layout.base +
963+
mod->arch.fdesc_offset;
964+
unsigned long end_opd = start_opd +
965+
mod->arch.fdesc_count * sizeof(Elf64_Fdesc);
966+
967+
if (ptr < (void *)start_opd || ptr >= (void *)end_opd)
968+
return ptr;
969+
970+
return dereference_function_descriptor(ptr);
971+
}
972+
#endif

arch/parisc/kernel/process.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,15 @@ void *dereference_function_descriptor(void *ptr)
315315
ptr = p;
316316
return ptr;
317317
}
318+
319+
void *dereference_kernel_function_descriptor(void *ptr)
320+
{
321+
if (ptr < (void *)__start_opd ||
322+
ptr >= (void *)__end_opd)
323+
return ptr;
324+
325+
return dereference_function_descriptor(ptr);
326+
}
318327
#endif
319328

320329
static inline unsigned long brk_rnd(void)

arch/parisc/kernel/vmlinux.lds.S

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ SECTIONS
100100
. = ALIGN(16);
101101
/* Linkage tables */
102102
.opd : {
103+
__start_opd = .;
103104
*(.opd)
105+
__end_opd = .;
104106
} PROVIDE (__gp = .);
105107
.plt : {
106108
*(.plt)

arch/powerpc/include/asm/module.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ struct mod_arch_specific {
4545
unsigned long tramp;
4646
#endif
4747

48+
/* For module function descriptor dereference */
49+
unsigned long start_opd;
50+
unsigned long end_opd;
4851
#else /* powerpc64 */
4952
/* Indices of PLT sections within module. */
5053
unsigned int core_plt_section;

arch/powerpc/include/asm/sections.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ static inline int overlaps_kvm_tmp(unsigned long start, unsigned long end)
6666
}
6767

6868
#ifdef PPC64_ELF_ABI_v1
69+
70+
#define HAVE_DEREFERENCE_FUNCTION_DESCRIPTOR 1
71+
6972
#undef dereference_function_descriptor
7073
static inline void *dereference_function_descriptor(void *ptr)
7174
{
@@ -76,6 +79,15 @@ static inline void *dereference_function_descriptor(void *ptr)
7679
ptr = p;
7780
return ptr;
7881
}
82+
83+
#undef dereference_kernel_function_descriptor
84+
static inline void *dereference_kernel_function_descriptor(void *ptr)
85+
{
86+
if (ptr < (void *)__start_opd || ptr >= (void *)__end_opd)
87+
return ptr;
88+
89+
return dereference_function_descriptor(ptr);
90+
}
7991
#endif /* PPC64_ELF_ABI_v1 */
8092

8193
#endif

0 commit comments

Comments
 (0)