linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* RFC: script to convert vsprintf uses of %pf to %ps and %pF to %pS
@ 2018-11-25  9:13 Joe Perches
  2018-11-26  5:35 ` Sergey Senozhatsky
  2018-11-30 16:58 ` Petr Mladek
  0 siblings, 2 replies; 5+ messages in thread
From: Joe Perches @ 2018-11-25  9:13 UTC (permalink / raw)
  To: Sergey Senozhatsky, Linus Torvalds; +Cc: LKML

commit 04b8eb7a4ccd ("symbol lookup: introduce dereference_symbol_descriptor()}"

deprecated vsprintf extension %pf and %pF.

There are approximately these total uses of the symbolic
lookup vsprintf extensions %p[SsFf]:

$ git grep '".*[^%]%p[SsFf]' | \
  grep -oh '%p[SsFf]' | sort | uniq -c | sort -rn
    231 %pS
     65 %ps
     60 %pf
     47 %pF

which is about a 3:1 ratio favoring %pS

so a script to convert all the %pf uses to %ps and %pF uses to %pS
could be useful.

There are a few files that appear should not be converted.

$ git grep -w --name-only -i '%pf'| \
  grep -vP '^(?:Documentation|tools|include/linux/freezer.h)'| \
  xargs sed -i -e 's/%pf/%ps/g' -e 's/%pF/%pS/g'

If that script above is run, it leaves the following patch
to be applied:
---
 Documentation/core-api/printk-formats.rst | 10 ----------
 lib/vsprintf.c                            | 12 ++----------
 2 files changed, 2 insertions(+), 20 deletions(-)

diff --git a/Documentation/core-api/printk-formats.rst b/Documentation/core-api/printk-formats.rst
index ff48b55040ef..ab5a6d1b05c0 100644
--- a/Documentation/core-api/printk-formats.rst
+++ b/Documentation/core-api/printk-formats.rst
@@ -70,8 +70,6 @@ Symbols/Function Pointers
 
 	%pS	versatile_init+0x0/0x110
 	%ps	versatile_init
-	%pF	versatile_init+0x0/0x110
-	%pf	versatile_init
 	%pSR	versatile_init+0x9/0x110
 		(with __builtin_extract_return_addr() translation)
 	%pB	prev_fn_of_versatile_init+0x88/0x88
@@ -81,14 +79,6 @@ The ``S`` and ``s`` specifiers are used for printing a pointer in symbolic
 format. They result in the symbol name with (S) or without (s)
 offsets. If KALLSYMS are disabled then the symbol address is printed instead.
 
-Note, that the ``F`` and ``f`` specifiers are identical to ``S`` (``s``)
-and thus deprecated. We have ``F`` and ``f`` because on ia64, ppc64 and
-parisc64 function pointers are indirect and, in fact, are function
-descriptors, which require additional dereferencing before we can lookup
-the symbol. As of now, ``S`` and ``s`` perform dereferencing on those
-platforms (when needed), so ``F`` and ``f`` exist for compatibility
-reasons only.
-
 The ``B`` specifier results in the symbol name with offsets and should be
 used when printing stack backtraces. The specifier takes into
 consideration the effect of compiler optimisations which may occur
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 37a54a6dd594..393002bf5298 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -795,7 +795,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
 #ifdef CONFIG_KALLSYMS
 	if (*fmt == 'B')
 		sprint_backtrace(sym, value);
-	else if (*fmt != 'f' && *fmt != 's')
+	else if (*fmt != 's')
 		sprint_symbol(sym, value);
 	else
 		sprint_symbol_no_offset(sym, value);
@@ -1756,9 +1756,7 @@ char *device_node_string(char *buf, char *end, struct device_node *dn,
  *
  * - 'S' For symbolic direct pointers (or function descriptors) with offset
  * - 's' For symbolic direct pointers (or function descriptors) without offset
- * - 'F' Same as 'S'
- * - 'f' Same as 's'
- * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
+ * - '[Ss]R' as above with __builtin_extract_return_addr() translation
  * - 'B' For backtraced symbolic direct pointers with offset
  * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
  * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
@@ -1872,8 +1870,6 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
 	}
 
 	switch (*fmt) {
-	case 'F':
-	case 'f':
 	case 'S':
 	case 's':
 		ptr = dereference_symbol_descriptor(ptr);
@@ -2603,8 +2599,6 @@ int vbin_printf(u32 *bin_buf, size_t size, const char *fmt, va_list args)
 			/* Dereference of functions is still OK */
 			case 'S':
 			case 's':
-			case 'F':
-			case 'f':
 			case 'x':
 			case 'K':
 				save_arg(void *);
@@ -2779,8 +2773,6 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
 			switch (*fmt) {
 			case 'S':
 			case 's':
-			case 'F':
-			case 'f':
 			case 'x':
 			case 'K':
 				process = true;
---



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: RFC: script to convert vsprintf uses of %pf to %ps and %pF to %pS
  2018-11-25  9:13 RFC: script to convert vsprintf uses of %pf to %ps and %pF to %pS Joe Perches
@ 2018-11-26  5:35 ` Sergey Senozhatsky
  2018-11-26  6:08   ` Sergey Senozhatsky
  2018-11-30 16:58 ` Petr Mladek
  1 sibling, 1 reply; 5+ messages in thread
From: Sergey Senozhatsky @ 2018-11-26  5:35 UTC (permalink / raw)
  To: Joe Perches; +Cc: Sergey Senozhatsky, Linus Torvalds, LKML

Hi,

Cc-ing Petr and Steven

On (11/25/18 01:13), Joe Perches wrote:
> commit 04b8eb7a4ccd ("symbol lookup: introduce dereference_symbol_descriptor()}"
> 
> deprecated vsprintf extension %pf and %pF.
> 
> There are approximately these total uses of the symbolic
> lookup vsprintf extensions %p[SsFf]:
> 
> $ git grep '".*[^%]%p[SsFf]' | \
>   grep -oh '%p[SsFf]' | sort | uniq -c | sort -rn
>     231 %pS
>      65 %ps
>      60 %pf
>      47 %pF

I didn't bother to remove "pf/pF" because I didn't want to count on:
  a) everyone running checkpatch.pl
  b) everyone testing all printk-s they added

I guess pf/pF still can sneak in.

But I don't have a really strong opinion on this. If general
consensus is that we shall remove deprecated specifiers, then
I'm fine.

> which is about a 3:1 ratio favoring %pS
> 
> so a script to convert all the %pf uses to %ps and %pF uses to %pS
> could be useful.
> 
> There are a few files that appear should not be converted.
> 
> $ git grep -w --name-only -i '%pf'| \
>   grep -vP '^(?:Documentation|tools|include/linux/freezer.h)'| \
>   xargs sed -i -e 's/%pf/%ps/g' -e 's/%pF/%pS/g'
> 
> If that script above is run, it leaves the following patch
> to be applied:

After running this script I still have a bunch of leftovers:

//
// these two are probably not really relevant, but still - %pF/%pf
//
tools/lib/traceevent/event-parse.c:             if (asprintf(&format, "%%pf: (NO FORMAT FOUND at %llx)\n", addr) < 0)
tools/lib/traceevent/event-parse.c:     if (asprintf(&format, "%s: %s", "%pf", printk->printk) < 0)

arch/um/kernel/sysrq.c: pr_info(" [<%08lx>] %s%pF\n", address, reliable ? "" : "? ",
arch/x86/xen/multicalls.c:                              printk(KERN_DEBUG "  call %2d/%d: op=%lu arg=[%lx] result=%ld\t%pF\n",
kernel/async.c:         pr_debug("calling  %lli_%pF @ %i\n",
kernel/async.c:         pr_debug("initcall %lli_%pF returned 0 after %lld usecs\n",

	-ss

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: RFC: script to convert vsprintf uses of %pf to %ps and %pF to %pS
  2018-11-26  5:35 ` Sergey Senozhatsky
@ 2018-11-26  6:08   ` Sergey Senozhatsky
  2018-11-26 17:13     ` Joe Perches
  0 siblings, 1 reply; 5+ messages in thread
From: Sergey Senozhatsky @ 2018-11-26  6:08 UTC (permalink / raw)
  To: Joe Perches
  Cc: Linus Torvalds, LKML, Steven Rostedt, Petr Mladek,
	Sergey Senozhatsky, Sergey Senozhatsky

And I forgot to actually Cc Petr and Steven...
Top-posting.

-------

Hi,

Cc-ing Petr and Steven

On (11/25/18 01:13), Joe Perches wrote:
> commit 04b8eb7a4ccd ("symbol lookup: introduce dereference_symbol_descriptor()}"
> 
> deprecated vsprintf extension %pf and %pF.
> 
> There are approximately these total uses of the symbolic
> lookup vsprintf extensions %p[SsFf]:
> 
> $ git grep '".*[^%]%p[SsFf]' | \
>   grep -oh '%p[SsFf]' | sort | uniq -c | sort -rn
>     231 %pS
>      65 %ps
>      60 %pf
>      47 %pF

I didn't bother to remove "pf/pF" because I didn't want to count on:
  a) everyone running checkpatch.pl
  b) everyone testing all printk-s they added

I guess pf/pF still can sneak in.

But I don't have a really strong opinion on this. If general
consensus is that we shall remove deprecated specifiers, then
I'm fine.

> which is about a 3:1 ratio favoring %pS
> 
> so a script to convert all the %pf uses to %ps and %pF uses to %pS
> could be useful.
> 
> There are a few files that appear should not be converted.
> 
> $ git grep -w --name-only -i '%pf'| \
>   grep -vP '^(?:Documentation|tools|include/linux/freezer.h)'| \
>   xargs sed -i -e 's/%pf/%ps/g' -e 's/%pF/%pS/g'
> 
> If that script above is run, it leaves the following patch
> to be applied:

After running this script I still have a bunch of leftovers:

//
// these two are probably not really relevant, but still - %pF/%pf
//
tools/lib/traceevent/event-parse.c:             if (asprintf(&format, "%%pf: (NO FORMAT FOUND at %llx)\n", addr) < 0)
tools/lib/traceevent/event-parse.c:     if (asprintf(&format, "%s: %s", "%pf", printk->printk) < 0)

arch/um/kernel/sysrq.c: pr_info(" [<%08lx>] %s%pF\n", address, reliable ? "" : "? ",
arch/x86/xen/multicalls.c:                              printk(KERN_DEBUG "  call %2d/%d: op=%lu arg=[%lx] result=%ld\t%pF\n",
kernel/async.c:         pr_debug("calling  %lli_%pF @ %i\n",
kernel/async.c:         pr_debug("initcall %lli_%pF returned 0 after %lld usecs\n",

	-ss

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: RFC: script to convert vsprintf uses of %pf to %ps and %pF to %pS
  2018-11-26  6:08   ` Sergey Senozhatsky
@ 2018-11-26 17:13     ` Joe Perches
  0 siblings, 0 replies; 5+ messages in thread
From: Joe Perches @ 2018-11-26 17:13 UTC (permalink / raw)
  To: Sergey Senozhatsky
  Cc: Linus Torvalds, LKML, Steven Rostedt, Petr Mladek, Sergey Senozhatsky

On Mon, 2018-11-26 at 15:08 +0900, Sergey Senozhatsky wrote:
> > There are approximately these total uses of the symbolic
> > lookup vsprintf extensions %p[SsFf]:
> > 
> > $ git grep '".*[^%]%p[SsFf]' | \
> >   grep -oh '%p[SsFf]' | sort | uniq -c | sort -rn
> >     231 %pS
> >      65 %ps
> >      60 %pf
> >      47 %pF
> 
> I didn't bother to remove "pf/pF" because I didn't want to count on:
>   a) everyone running checkpatch.pl
>   b) everyone testing all printk-s they added
> 
> I guess pf/pF still can sneak in.

Any use of %p<invalid_extension> could sneak in.

And thanks, the checkpatch test for %p<invalid_extensions>
should be updated too.

> But I don't have a really strong opinion on this. If general
> consensus is that we shall remove deprecated specifiers, then
> I'm fine.

I think converting deprecated things is generally good.

Also, the %p<extension> lettering space is limited, so
cleaning deprecated extensions is useful.

> After running this script I still have a bunch of leftovers:
> 
> //
> // these two are probably not really relevant, but still - %pF/%pf
> //
> tools/lib/traceevent/event-parse.c:             if (asprintf(&format, "%%pf: (NO FORMAT FOUND at %llx)\n", addr) < 0)
> tools/lib/traceevent/event-parse.c:     if (asprintf(&format, "%s: %s", "%pf", printk->printk) < 0)

I was not/am not sure about those.

> arch/um/kernel/sysrq.c: pr_info(" [<%08lx>] %s%pF\n", address, reliable ? "" : "? ",
> arch/x86/xen/multicalls.c:                              printk(KERN_DEBUG "  call %2d/%d: op=%lu arg=[%lx] result=%ld\t%pF\n",
> kernel/async.c:         pr_debug("calling  %lli_%pF @ %i\n",
> kernel/async.c:         pr_debug("initcall %lli_%pF returned 0 after %lld usecs\n",

Missed those by using \b, thanks again.



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: RFC: script to convert vsprintf uses of %pf to %ps and %pF to %pS
  2018-11-25  9:13 RFC: script to convert vsprintf uses of %pf to %ps and %pF to %pS Joe Perches
  2018-11-26  5:35 ` Sergey Senozhatsky
@ 2018-11-30 16:58 ` Petr Mladek
  1 sibling, 0 replies; 5+ messages in thread
From: Petr Mladek @ 2018-11-30 16:58 UTC (permalink / raw)
  To: Joe Perches; +Cc: Sergey Senozhatsky, Linus Torvalds, LKML, Steven Rostedt

On Sun 2018-11-25 01:13:51, Joe Perches wrote:
> commit 04b8eb7a4ccd ("symbol lookup: introduce dereference_symbol_descriptor()}"
> 
> deprecated vsprintf extension %pf and %pF.
> 
> so a script to convert all the %pf uses to %ps and %pF uses to %pS
> could be useful.
> 
> There are a few files that appear should not be converted.
> 
> $ git grep -w --name-only -i '%pf'| \
>   grep -vP '^(?:Documentation|tools|include/linux/freezer.h)'| \
>   xargs sed -i -e 's/%pf/%ps/g' -e 's/%pF/%pS/g'
> 
> If that script above is run, it leaves the following patch
> to be applied:

> diff --git a/lib/vsprintf.c b/lib/vsprintf.c
> index 37a54a6dd594..393002bf5298 100644
> --- a/lib/vsprintf.c
> +++ b/lib/vsprintf.c
> @@ -1872,8 +1870,6 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
>  	}
>  
>  	switch (*fmt) {
> -	case 'F':
> -	case 'f':

Please, keep handling these modifiers so that they do not get reused
anytime soon.

The pointer modifiers are evil. Any misuse can easily lead to a crash.
Any mistakes with upstreaming 3rd party patches or backporting stable
fixes would be hard to notice.

Well, it is perfectly fine to just explicitly fallback to
the default %p behavior. I mean something like:

	case 'F':
	case 'f':
		/* Replaced by %ps and %pS and removed in 4.21 */
		break;

Best Regards,
Petr

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-11-30 16:58 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-25  9:13 RFC: script to convert vsprintf uses of %pf to %ps and %pF to %pS Joe Perches
2018-11-26  5:35 ` Sergey Senozhatsky
2018-11-26  6:08   ` Sergey Senozhatsky
2018-11-26 17:13     ` Joe Perches
2018-11-30 16:58 ` Petr Mladek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).