linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH -next] lib/vsprintf: Make function pointer_string static
@ 2019-04-26 16:46 Yue Haibing
  2019-04-26 17:02 ` Steven Rostedt
  0 siblings, 1 reply; 8+ messages in thread
From: Yue Haibing @ 2019-04-26 16:46 UTC (permalink / raw)
  To: pmladek, sergey.senozhatsky, andriy.shevchenko, geert+renesas,
	rostedt, me
  Cc: linux-kernel, YueHaibing

From: YueHaibing <yuehaibing@huawei.com>

Fix sparse warning:

lib/vsprintf.c:673:6: warning:
 symbol 'pointer_string' was not declared. Should it be static?

Signed-off-by: YueHaibing <yuehaibing@huawei.com>
---
 lib/vsprintf.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 1f367f3..7b0a614 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -670,8 +670,9 @@ char *string(char *buf, char *end, const char *s,
 	return string_nocheck(buf, end, s, spec);
 }
 
-char *pointer_string(char *buf, char *end, const void *ptr,
-		     struct printf_spec spec)
+static char *pointer_string(char *buf, char *end,
+			    const void *ptr,
+			    struct printf_spec spec)
 {
 	spec.base = 16;
 	spec.flags |= SMALL;
-- 
2.7.4



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

* Re: [PATCH -next] lib/vsprintf: Make function pointer_string static
  2019-04-26 16:46 [PATCH -next] lib/vsprintf: Make function pointer_string static Yue Haibing
@ 2019-04-26 17:02 ` Steven Rostedt
  2019-04-29 11:08   ` Petr Mladek
  0 siblings, 1 reply; 8+ messages in thread
From: Steven Rostedt @ 2019-04-26 17:02 UTC (permalink / raw)
  To: Yue Haibing
  Cc: pmladek, sergey.senozhatsky, andriy.shevchenko, geert+renesas,
	me, linux-kernel, Andrew Morton

On Sat, 27 Apr 2019 00:46:30 +0800
Yue Haibing <yuehaibing@huawei.com> wrote:

> From: YueHaibing <yuehaibing@huawei.com>
> 
> Fix sparse warning:
> 
> lib/vsprintf.c:673:6: warning:
>  symbol 'pointer_string' was not declared. Should it be static?
> 
> Signed-off-by: YueHaibing <yuehaibing@huawei.com>
> ---
>  lib/vsprintf.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/lib/vsprintf.c b/lib/vsprintf.c
> index 1f367f3..7b0a614 100644
> --- a/lib/vsprintf.c
> +++ b/lib/vsprintf.c
> @@ -670,8 +670,9 @@ char *string(char *buf, char *end, const char *s,
>  	return string_nocheck(buf, end, s, spec);
>  }
>  
> -char *pointer_string(char *buf, char *end, const void *ptr,
> -		     struct printf_spec spec)
> +static char *pointer_string(char *buf, char *end,

Looks like commit "vsprintf: Do not check address of well-known
strings" removed the: "static noinline_for_stack"

Does pointer_string() need that still?

Petr?

-- Steve


> +			    const void *ptr,
> +			    struct printf_spec spec)
>  {
>  	spec.base = 16;
>  	spec.flags |= SMALL;


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

* Re: [PATCH -next] lib/vsprintf: Make function pointer_string static
  2019-04-26 17:02 ` Steven Rostedt
@ 2019-04-29 11:08   ` Petr Mladek
  2019-04-29 13:13     ` Steven Rostedt
  0 siblings, 1 reply; 8+ messages in thread
From: Petr Mladek @ 2019-04-29 11:08 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: Yue Haibing, sergey.senozhatsky, andriy.shevchenko,
	geert+renesas, me, linux-kernel, Andrew Morton

On Fri 2019-04-26 13:02:04, Steven Rostedt wrote:
> On Sat, 27 Apr 2019 00:46:30 +0800
> Yue Haibing <yuehaibing@huawei.com> wrote:
> 
> > From: YueHaibing <yuehaibing@huawei.com>
> > 
> > Fix sparse warning:
> > 
> > lib/vsprintf.c:673:6: warning:
> >  symbol 'pointer_string' was not declared. Should it be static?
> > 
> > Signed-off-by: YueHaibing <yuehaibing@huawei.com>
> > ---
> >  lib/vsprintf.c | 5 +++--
> >  1 file changed, 3 insertions(+), 2 deletions(-)
> > 
> > diff --git a/lib/vsprintf.c b/lib/vsprintf.c
> > index 1f367f3..7b0a614 100644
> > --- a/lib/vsprintf.c
> > +++ b/lib/vsprintf.c
> > @@ -670,8 +670,9 @@ char *string(char *buf, char *end, const char *s,
> >  	return string_nocheck(buf, end, s, spec);
> >  }
> >  
> > -char *pointer_string(char *buf, char *end, const void *ptr,
> > -		     struct printf_spec spec)
> > +static char *pointer_string(char *buf, char *end,
> 
> Looks like commit "vsprintf: Do not check address of well-known
> strings" removed the: "static noinline_for_stack"
> 
> Does pointer_string() need that still?

Heh, it was removed by mistake and well hidden in the diff.

I have pushed Yue's fix into printk.git, branch
for-5.2-vsprintf-hardening

Thanks for the patch.

Best Regards,
Petr

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

* Re: [PATCH -next] lib/vsprintf: Make function pointer_string static
  2019-04-29 11:08   ` Petr Mladek
@ 2019-04-29 13:13     ` Steven Rostedt
  2019-04-29 14:30       ` Petr Mladek
  0 siblings, 1 reply; 8+ messages in thread
From: Steven Rostedt @ 2019-04-29 13:13 UTC (permalink / raw)
  To: Petr Mladek
  Cc: Yue Haibing, sergey.senozhatsky, andriy.shevchenko,
	geert+renesas, me, linux-kernel, Andrew Morton

On Mon, 29 Apr 2019 13:08:01 +0200
Petr Mladek <pmladek@suse.com> wrote:

> > Looks like commit "vsprintf: Do not check address of well-known
> > strings" removed the: "static noinline_for_stack"
> > 
> > Does pointer_string() need that still?  
> 
> Heh, it was removed by mistake and well hidden in the diff.
> 
> I have pushed Yue's fix into printk.git, branch
> for-5.2-vsprintf-hardening
> 
> Thanks for the patch.

But doesn't it still need the "noinline_for_stack", that doesn't look
like it changed.

-- Steve

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

* Re: [PATCH -next] lib/vsprintf: Make function pointer_string static
  2019-04-29 13:13     ` Steven Rostedt
@ 2019-04-29 14:30       ` Petr Mladek
  2019-04-29 14:39         ` Steven Rostedt
  0 siblings, 1 reply; 8+ messages in thread
From: Petr Mladek @ 2019-04-29 14:30 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: Yue Haibing, sergey.senozhatsky, andriy.shevchenko,
	geert+renesas, me, linux-kernel, Andrew Morton

On Mon 2019-04-29 09:13:20, Steven Rostedt wrote:
> On Mon, 29 Apr 2019 13:08:01 +0200
> Petr Mladek <pmladek@suse.com> wrote:
> 
> > > Looks like commit "vsprintf: Do not check address of well-known
> > > strings" removed the: "static noinline_for_stack"
> > > 
> > > Does pointer_string() need that still?  
> > 
> > Heh, it was removed by mistake and well hidden in the diff.
> > 
> > I have pushed Yue's fix into printk.git, branch
> > for-5.2-vsprintf-hardening
> > 
> > Thanks for the patch.
> 
> But doesn't it still need the "noinline_for_stack", that doesn't look
> like it changed.

Good question. I have just double checked it. And pointer_string() with
"noinline_for_stack" does not make any difference in the stack
usage here.


I actually played with this before:

"noinline_for_stack" is a black magic added by
the commit cf3b429b03e827c7180 ("vsprintf.c: use noinline_for_stack").

It is evidently useful in some cases. But I somehow doubt
that it really makes things better when used everywhere.
Therefore I have got a bit relaxed and omitted it in most
newly added functions that did not affect the results.

They are the same before and after the patchset:

pmladek@pathway:/prace/kernel/linux-printk> objdump -d lib/vsprintf.o | perl scripts/checkstack.pl
0x00000e12 symbol_string [vsprintf.o]:                  248
0x00000e6d symbol_string [vsprintf.o]:                  248
0x000012fb ip6_addr_string_sa [vsprintf.o]:             112
0x00001415 ip6_addr_string_sa [vsprintf.o]:             112
0x000028c6 resource_string.isra.9 [vsprintf.o]:         104
0x00002964 resource_string.isra.9 [vsprintf.o]:         104


Would you like to fix this clearly, for example, rebase and
put both "static noinline_for_stack" back or add yet
another commit or?

IMHO, it is not too important. Anyway, I am open for any
advice. I do not want to create more mess.

Best Regards,
Petr

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

* Re: [PATCH -next] lib/vsprintf: Make function pointer_string static
  2019-04-29 14:30       ` Petr Mladek
@ 2019-04-29 14:39         ` Steven Rostedt
  2019-04-29 16:42           ` Joe Perches
  0 siblings, 1 reply; 8+ messages in thread
From: Steven Rostedt @ 2019-04-29 14:39 UTC (permalink / raw)
  To: Petr Mladek
  Cc: Yue Haibing, sergey.senozhatsky, andriy.shevchenko,
	geert+renesas, me, linux-kernel, Andrew Morton, Joe Perches


[ added Joe ]

On Mon, 29 Apr 2019 16:30:37 +0200
Petr Mladek <pmladek@suse.com> wrote:

> On Mon 2019-04-29 09:13:20, Steven Rostedt wrote:
> > On Mon, 29 Apr 2019 13:08:01 +0200
> > Petr Mladek <pmladek@suse.com> wrote:
> >   
> > > > Looks like commit "vsprintf: Do not check address of well-known
> > > > strings" removed the: "static noinline_for_stack"
> > > > 
> > > > Does pointer_string() need that still?    
> > > 
> > > Heh, it was removed by mistake and well hidden in the diff.
> > > 
> > > I have pushed Yue's fix into printk.git, branch
> > > for-5.2-vsprintf-hardening
> > > 
> > > Thanks for the patch.  
> > 
> > But doesn't it still need the "noinline_for_stack", that doesn't look
> > like it changed.  
> 
> Good question. I have just double checked it. And pointer_string() with
> "noinline_for_stack" does not make any difference in the stack
> usage here.
> 
> 
> I actually played with this before:
> 
> "noinline_for_stack" is a black magic added by
> the commit cf3b429b03e827c7180 ("vsprintf.c: use noinline_for_stack").

From what I understand, "noinline_for_stack" is just noinline and the
"for_stack" part is just to document that the noinline is used for
stack purposes. If the compiler doesn't inline the function without the
noinline, then it wont make any difference.

The point was to not inline the function because it can be used in
stack critical areas, and that it's better to do the call than to
increase the stack.

Although the commit you posted is back in 2010, and compilers and I
think even our stack size has changed since then. This may not be a
critical issue today, and just making it static and letting the
compiler decide might be the right solution.

Let's add Yue's patch as is for now, and perhaps revisit this as a
separate thread.

-- Steve

> 
> It is evidently useful in some cases. But I somehow doubt
> that it really makes things better when used everywhere.
> Therefore I have got a bit relaxed and omitted it in most
> newly added functions that did not affect the results.
> 
> They are the same before and after the patchset:
> 
> pmladek@pathway:/prace/kernel/linux-printk> objdump -d lib/vsprintf.o | perl scripts/checkstack.pl
> 0x00000e12 symbol_string [vsprintf.o]:                  248
> 0x00000e6d symbol_string [vsprintf.o]:                  248
> 0x000012fb ip6_addr_string_sa [vsprintf.o]:             112
> 0x00001415 ip6_addr_string_sa [vsprintf.o]:             112
> 0x000028c6 resource_string.isra.9 [vsprintf.o]:         104
> 0x00002964 resource_string.isra.9 [vsprintf.o]:         104
> 
> 
> Would you like to fix this clearly, for example, rebase and
> put both "static noinline_for_stack" back or add yet
> another commit or?
> 
> IMHO, it is not too important. Anyway, I am open for any
> advice. I do not want to create more mess.
> 
> Best Regards,
> Petr


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

* Re: [PATCH -next] lib/vsprintf: Make function pointer_string static
  2019-04-29 14:39         ` Steven Rostedt
@ 2019-04-29 16:42           ` Joe Perches
  2019-04-30  8:42             ` Petr Mladek
  0 siblings, 1 reply; 8+ messages in thread
From: Joe Perches @ 2019-04-29 16:42 UTC (permalink / raw)
  To: Steven Rostedt, Petr Mladek
  Cc: Yue Haibing, sergey.senozhatsky, andriy.shevchenko,
	geert+renesas, me, linux-kernel, Andrew Morton

On Mon, 2019-04-29 at 10:39 -0400, Steven Rostedt wrote:
> [ added Joe ]
> > Good question. I have just double checked it. And pointer_string() with
> > "noinline_for_stack" does not make any difference in the stack
> > usage here.
> > 
> > I actually played with this before:
> > 
> > "noinline_for_stack" is a black magic added by
> > the commit cf3b429b03e827c7180 ("vsprintf.c: use noinline_for_stack").
> 
> From what I understand, "noinline_for_stack" is just noinline and the
> "for_stack" part is just to document that the noinline is used for
> stack purposes. If the compiler doesn't inline the function without the
> noinline, then it wont make any difference.
> 
> The point was to not inline the function because it can be used in
> stack critical areas, and that it's better to do the call than to
> increase the stack.

It was added because of %pV is recursive and recursive
functions can eat
a lot of stack.

Using noinline_for_stack was just a bit more self-documenting.

I do still think it's a useful notation.


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

* Re: [PATCH -next] lib/vsprintf: Make function pointer_string static
  2019-04-29 16:42           ` Joe Perches
@ 2019-04-30  8:42             ` Petr Mladek
  0 siblings, 0 replies; 8+ messages in thread
From: Petr Mladek @ 2019-04-30  8:42 UTC (permalink / raw)
  To: Joe Perches
  Cc: Steven Rostedt, Yue Haibing, sergey.senozhatsky,
	andriy.shevchenko, geert+renesas, me, linux-kernel,
	Andrew Morton

On Mon 2019-04-29 09:42:30, Joe Perches wrote:
> On Mon, 2019-04-29 at 10:39 -0400, Steven Rostedt wrote:
> > [ added Joe ]
> > > Good question. I have just double checked it. And pointer_string() with
> > > "noinline_for_stack" does not make any difference in the stack
> > > usage here.
> > > 
> > > I actually played with this before:
> > > 
> > > "noinline_for_stack" is a black magic added by
> > > the commit cf3b429b03e827c7180 ("vsprintf.c: use noinline_for_stack").
> > 
> > From what I understand, "noinline_for_stack" is just noinline and the
> > "for_stack" part is just to document that the noinline is used for
> > stack purposes. If the compiler doesn't inline the function without the
> > noinline, then it wont make any difference.
> > 
> > The point was to not inline the function because it can be used in
> > stack critical areas, and that it's better to do the call than to
> > increase the stack.
> 
> It was added because of %pV is recursive and recursive
> functions can eat
> a lot of stack.
> 
> Using noinline_for_stack was just a bit more self-documenting.
> 
> I do still think it's a useful notation.

I understand the problem and noinline_for_stack improved some
paths definitely.

On the other hand, the call instruction uses the stack as well.
Note that many of the annotated functions have 5 parameters.

I believe that some of the annotated functions might get inlined
with a lower stack usage in the caller than what is needed
by the call.

The problem is that it depends on the used compiler, optimization,
and architecture. I personally do not want to invest much time
into optimizing this unless people report real life problems.

Best Regards,
Petr

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

end of thread, other threads:[~2019-04-30  8:42 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-26 16:46 [PATCH -next] lib/vsprintf: Make function pointer_string static Yue Haibing
2019-04-26 17:02 ` Steven Rostedt
2019-04-29 11:08   ` Petr Mladek
2019-04-29 13:13     ` Steven Rostedt
2019-04-29 14:30       ` Petr Mladek
2019-04-29 14:39         ` Steven Rostedt
2019-04-29 16:42           ` Joe Perches
2019-04-30  8:42             ` 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).