public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] perf symbols: Fix symbol size calculation condition
@ 2022-03-17 13:55 Michael Petlan
  2022-03-17 15:37 ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 3+ messages in thread
From: Michael Petlan @ 2022-03-17 13:55 UTC (permalink / raw)
  To: linux-kernel; +Cc: linux-perf-users, acme, jolsa, atrajeev, maddy, kjain

Before this patch, the symbol end address fixup to be called, needed two
conditions being met:

  if (prev->end == prev->start && prev->end != curr->start)

Where
  "prev->end == prev->start" means that prev is zero-long
                             (and thus needs a fixup)
and
  "prev->end != curr->start" means that fixup hasn't been applied yet

However, this logic is incorrect in the following situation:

*curr  = {rb_node = {__rb_parent_color = 278218928,
  rb_right = 0x0, rb_left = 0x0},
  start = 0xc000000000062354,
  end = 0xc000000000062354, namelen = 40, type = 2 '\002',
  binding = 0 '\000', idle = 0 '\000', ignore = 0 '\000',
  inlined = 0 '\000', arch_sym = 0 '\000', annotate2 = false,
  name = 0x1159739e "kprobe_optinsn_page\t[__builtin__kprobes]"}

*prev = {rb_node = {__rb_parent_color = 278219041,
  rb_right = 0x109548b0, rb_left = 0x109547c0},
  start = 0xc000000000062354,
  end = 0xc000000000062354, namelen = 12, type = 2 '\002',
  binding = 1 '\001', idle = 0 '\000', ignore = 0 '\000',
  inlined = 0 '\000', arch_sym = 0 '\000', annotate2 = false,
  name = 0x1095486e "optinsn_slot"}

In this case, prev->start == prev->end == curr->start == curr->end,
thus the condition above thinks that "we need a fixup due to zero
length of prev symbol, but it has been probably done, since the
prev->end == curr->start", which is wrong.

After the patch, the execution path proceeds to arch__symbols__fixup_end
function which fixes up the size of prev symbol by adding page_size to
its end offset.

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
---
 tools/perf/util/symbol.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index fb075aa8f8f2..dea0fc495185 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -231,7 +231,7 @@ void symbols__fixup_end(struct rb_root_cached *symbols)
 		prev = curr;
 		curr = rb_entry(nd, struct symbol, rb_node);
 
-		if (prev->end == prev->start && prev->end != curr->start)
+		if (prev->end == prev->start || prev->end != curr->start)
 			arch__symbols__fixup_end(prev, curr);
 	}
 
-- 
2.18.4


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

* Re: [PATCH] perf symbols: Fix symbol size calculation condition
  2022-03-17 13:55 [PATCH] perf symbols: Fix symbol size calculation condition Michael Petlan
@ 2022-03-17 15:37 ` Arnaldo Carvalho de Melo
  2022-03-17 17:49   ` Michael Petlan
  0 siblings, 1 reply; 3+ messages in thread
From: Arnaldo Carvalho de Melo @ 2022-03-17 15:37 UTC (permalink / raw)
  To: Michael Petlan
  Cc: linux-kernel, linux-perf-users, jolsa, atrajeev, maddy, kjain

Em Thu, Mar 17, 2022 at 02:55:36PM +0100, Michael Petlan escreveu:
> Before this patch, the symbol end address fixup to be called, needed two
> conditions being met:
> 
>   if (prev->end == prev->start && prev->end != curr->start)
> 
> Where
>   "prev->end == prev->start" means that prev is zero-long
>                              (and thus needs a fixup)
> and
>   "prev->end != curr->start" means that fixup hasn't been applied yet
> 
> However, this logic is incorrect in the following situation:
> 
> *curr  = {rb_node = {__rb_parent_color = 278218928,
>   rb_right = 0x0, rb_left = 0x0},
>   start = 0xc000000000062354,
>   end = 0xc000000000062354, namelen = 40, type = 2 '\002',
>   binding = 0 '\000', idle = 0 '\000', ignore = 0 '\000',
>   inlined = 0 '\000', arch_sym = 0 '\000', annotate2 = false,
>   name = 0x1159739e "kprobe_optinsn_page\t[__builtin__kprobes]"}
> 
> *prev = {rb_node = {__rb_parent_color = 278219041,
>   rb_right = 0x109548b0, rb_left = 0x109547c0},
>   start = 0xc000000000062354,
>   end = 0xc000000000062354, namelen = 12, type = 2 '\002',
>   binding = 1 '\001', idle = 0 '\000', ignore = 0 '\000',
>   inlined = 0 '\000', arch_sym = 0 '\000', annotate2 = false,
>   name = 0x1095486e "optinsn_slot"}
> 
> In this case, prev->start == prev->end == curr->start == curr->end,
> thus the condition above thinks that "we need a fixup due to zero
> length of prev symbol, but it has been probably done, since the
> prev->end == curr->start", which is wrong.
> 
> After the patch, the execution path proceeds to arch__symbols__fixup_end
> function which fixes up the size of prev symbol by adding page_size to
> its end offset.

You missed this:

Fixes: 3b01a413c196c910 ("perf symbols: Improve kallsyms symbol end addr calculation")

I'll add it to the patch, ok?

- Arnaldo
 
> Signed-off-by: Michael Petlan <mpetlan@redhat.com>
> ---
>  tools/perf/util/symbol.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
> index fb075aa8f8f2..dea0fc495185 100644
> --- a/tools/perf/util/symbol.c
> +++ b/tools/perf/util/symbol.c
> @@ -231,7 +231,7 @@ void symbols__fixup_end(struct rb_root_cached *symbols)
>  		prev = curr;
>  		curr = rb_entry(nd, struct symbol, rb_node);
>  
> -		if (prev->end == prev->start && prev->end != curr->start)
> +		if (prev->end == prev->start || prev->end != curr->start)
>  			arch__symbols__fixup_end(prev, curr);
>  	}
>  
> -- 
> 2.18.4

-- 

- Arnaldo

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

* Re: [PATCH] perf symbols: Fix symbol size calculation condition
  2022-03-17 15:37 ` Arnaldo Carvalho de Melo
@ 2022-03-17 17:49   ` Michael Petlan
  0 siblings, 0 replies; 3+ messages in thread
From: Michael Petlan @ 2022-03-17 17:49 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: linux-kernel, linux-perf-users, jolsa, atrajeev, maddy, kjain

On Thu, 17 Mar 2022, Arnaldo Carvalho de Melo wrote:
> Em Thu, Mar 17, 2022 at 02:55:36PM +0100, Michael Petlan escreveu:
> > Before this patch, the symbol end address fixup to be called, needed two
> > conditions being met:
> > 
> >   if (prev->end == prev->start && prev->end != curr->start)
> > 
> > Where
> >   "prev->end == prev->start" means that prev is zero-long
> >                              (and thus needs a fixup)
> > and
> >   "prev->end != curr->start" means that fixup hasn't been applied yet
> > 
> > However, this logic is incorrect in the following situation:
> > 
> > *curr  = {rb_node = {__rb_parent_color = 278218928,
> >   rb_right = 0x0, rb_left = 0x0},
> >   start = 0xc000000000062354,
> >   end = 0xc000000000062354, namelen = 40, type = 2 '\002',
> >   binding = 0 '\000', idle = 0 '\000', ignore = 0 '\000',
> >   inlined = 0 '\000', arch_sym = 0 '\000', annotate2 = false,
> >   name = 0x1159739e "kprobe_optinsn_page\t[__builtin__kprobes]"}
> > 
> > *prev = {rb_node = {__rb_parent_color = 278219041,
> >   rb_right = 0x109548b0, rb_left = 0x109547c0},
> >   start = 0xc000000000062354,
> >   end = 0xc000000000062354, namelen = 12, type = 2 '\002',
> >   binding = 1 '\001', idle = 0 '\000', ignore = 0 '\000',
> >   inlined = 0 '\000', arch_sym = 0 '\000', annotate2 = false,
> >   name = 0x1095486e "optinsn_slot"}
> > 
> > In this case, prev->start == prev->end == curr->start == curr->end,
> > thus the condition above thinks that "we need a fixup due to zero
> > length of prev symbol, but it has been probably done, since the
> > prev->end == curr->start", which is wrong.
> > 
> > After the patch, the execution path proceeds to arch__symbols__fixup_end
> > function which fixes up the size of prev symbol by adding page_size to
> > its end offset.
> 
> You missed this:
> 
> Fixes: 3b01a413c196c910 ("perf symbols: Improve kallsyms symbol end addr calculation")
> 
> I'll add it to the patch, ok?

Sure thing. Thanks.
M

> 
> - Arnaldo
>  
> > Signed-off-by: Michael Petlan <mpetlan@redhat.com>
> > ---
> >  tools/perf/util/symbol.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
> > index fb075aa8f8f2..dea0fc495185 100644
> > --- a/tools/perf/util/symbol.c
> > +++ b/tools/perf/util/symbol.c
> > @@ -231,7 +231,7 @@ void symbols__fixup_end(struct rb_root_cached *symbols)
> >  		prev = curr;
> >  		curr = rb_entry(nd, struct symbol, rb_node);
> >  
> > -		if (prev->end == prev->start && prev->end != curr->start)
> > +		if (prev->end == prev->start || prev->end != curr->start)
> >  			arch__symbols__fixup_end(prev, curr);
> >  	}
> >  
> > -- 
> > 2.18.4
> 
> -- 
> 
> - Arnaldo
> 
> 


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

end of thread, other threads:[~2022-03-17 17:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-03-17 13:55 [PATCH] perf symbols: Fix symbol size calculation condition Michael Petlan
2022-03-17 15:37 ` Arnaldo Carvalho de Melo
2022-03-17 17:49   ` Michael Petlan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox