linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ftrace: return first found result in lookup_rec()
@ 2020-03-06  8:10 Artem Savkov
  2020-03-06 17:12 ` Steven Rostedt
  0 siblings, 1 reply; 4+ messages in thread
From: Artem Savkov @ 2020-03-06  8:10 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: linux-kernel, live-patching, Artem Savkov

It appears that ip ranges can overlap so. In that case lookup_rec()
returns whatever results it got last even if it found nothing in last
searched page.

This breaks an obscure livepatch late module patching usecase:
  - load livepatch
  - load the patched module
  - unload livepatch
  - try to load livepatch again

To fix this return from lookup_rec() as soon as it found the record
containing searched-for ip. This used to be this way prior lookup_rec()
introduction.

Fixes: 7e16f581a817 ("ftrace: Separate out functionality from ftrace_location_range()")
Signed-off-by: Artem Savkov <asavkov@redhat.com>
---
 kernel/trace/ftrace.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index 3f7ee102868a..b0f5ee1fd6e4 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -1547,8 +1547,10 @@ static struct dyn_ftrace *lookup_rec(unsigned long start, unsigned long end)
 		rec = bsearch(&key, pg->records, pg->index,
 			      sizeof(struct dyn_ftrace),
 			      ftrace_cmp_recs);
+		if (rec)
+			return rec;
 	}
-	return rec;
+	return NULL;
 }
 
 /**
-- 
2.21.1


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

* Re: [PATCH] ftrace: return first found result in lookup_rec()
  2020-03-06  8:10 [PATCH] ftrace: return first found result in lookup_rec() Artem Savkov
@ 2020-03-06 17:12 ` Steven Rostedt
  2020-03-06 17:43   ` [PATCH v2] " Artem Savkov
  0 siblings, 1 reply; 4+ messages in thread
From: Steven Rostedt @ 2020-03-06 17:12 UTC (permalink / raw)
  To: Artem Savkov; +Cc: linux-kernel, live-patching

On Fri,  6 Mar 2020 09:10:35 +0100
Artem Savkov <asavkov@redhat.com> wrote:

> It appears that ip ranges can overlap so. In that case lookup_rec()
> returns whatever results it got last even if it found nothing in last
> searched page.
> 
> This breaks an obscure livepatch late module patching usecase:
>   - load livepatch
>   - load the patched module
>   - unload livepatch
>   - try to load livepatch again
> 
> To fix this return from lookup_rec() as soon as it found the record
> containing searched-for ip. This used to be this way prior lookup_rec()
> introduction.
> 
> Fixes: 7e16f581a817 ("ftrace: Separate out functionality from ftrace_location_range()")
> Signed-off-by: Artem Savkov <asavkov@redhat.com>
> ---
>  kernel/trace/ftrace.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
> index 3f7ee102868a..b0f5ee1fd6e4 100644
> --- a/kernel/trace/ftrace.c
> +++ b/kernel/trace/ftrace.c
> @@ -1547,8 +1547,10 @@ static struct dyn_ftrace *lookup_rec(unsigned long start, unsigned long end)
>  		rec = bsearch(&key, pg->records, pg->index,
>  			      sizeof(struct dyn_ftrace),
>  			      ftrace_cmp_recs);

how about just adding:

		if (rec)
			break;

as that will do the same thing without adding two returns.

-- Steve

> +		if (rec)
> +			return rec;
>  	}
> -	return rec;
> +	return NULL;
>  }
>  
>  /**


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

* [PATCH v2] ftrace: return first found result in lookup_rec()
  2020-03-06 17:12 ` Steven Rostedt
@ 2020-03-06 17:43   ` Artem Savkov
  2020-03-10 19:38     ` Steven Rostedt
  0 siblings, 1 reply; 4+ messages in thread
From: Artem Savkov @ 2020-03-06 17:43 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: linux-kernel, live-patching, Artem Savkov

It appears that ip ranges can overlap so. In that case lookup_rec()
returns whatever results it got last even if it found nothing in last
searched page.

This breaks an obscure livepatch late module patching usecase:
  - load livepatch
  - load the patched module
  - unload livepatch
  - try to load livepatch again

To fix this return from lookup_rec() as soon as it found the record
containing searched-for ip. This used to be this way prior lookup_rec()
introduction.

v2: break instead of two returns

Fixes: 7e16f581a817 ("ftrace: Separate out functionality from ftrace_location_range()")
Signed-off-by: Artem Savkov <asavkov@redhat.com>
---
 kernel/trace/ftrace.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index 3f7ee102868a..fd81c7de77a7 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -1547,6 +1547,8 @@ static struct dyn_ftrace *lookup_rec(unsigned long start, unsigned long end)
 		rec = bsearch(&key, pg->records, pg->index,
 			      sizeof(struct dyn_ftrace),
 			      ftrace_cmp_recs);
+		if (rec)
+			break;
 	}
 	return rec;
 }
-- 
2.21.1


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

* Re: [PATCH v2] ftrace: return first found result in lookup_rec()
  2020-03-06 17:43   ` [PATCH v2] " Artem Savkov
@ 2020-03-10 19:38     ` Steven Rostedt
  0 siblings, 0 replies; 4+ messages in thread
From: Steven Rostedt @ 2020-03-10 19:38 UTC (permalink / raw)
  To: Artem Savkov; +Cc: linux-kernel, live-patching

On Fri,  6 Mar 2020 18:43:17 +0100
Artem Savkov <asavkov@redhat.com> wrote:

> It appears that ip ranges can overlap so. In that case lookup_rec()
> returns whatever results it got last even if it found nothing in last
> searched page.
> 
> This breaks an obscure livepatch late module patching usecase:
>   - load livepatch
>   - load the patched module
>   - unload livepatch
>   - try to load livepatch again
> 
> To fix this return from lookup_rec() as soon as it found the record
> containing searched-for ip. This used to be this way prior lookup_rec()
> introduction.
> 
> v2: break instead of two returns

Thanks Artem, I applied your patch. But just an FYI, it's best to place the
"v2" statement below the three dashes "---" so that it doesn't get pulled
into the git commit when this patch is applied via a script.

-- Steve

> 
> Fixes: 7e16f581a817 ("ftrace: Separate out functionality from ftrace_location_range()")
> Signed-off-by: Artem Savkov <asavkov@redhat.com>
> ---
>  kernel/trace/ftrace.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
> index 3f7ee102868a..fd81c7de77a7 100644
> --- a/kernel/trace/ftrace.c
> +++ b/kernel/trace/ftrace.c
> @@ -1547,6 +1547,8 @@ static struct dyn_ftrace *lookup_rec(unsigned long start, unsigned long end)
>  		rec = bsearch(&key, pg->records, pg->index,
>  			      sizeof(struct dyn_ftrace),
>  			      ftrace_cmp_recs);
> +		if (rec)
> +			break;
>  	}
>  	return rec;
>  }


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

end of thread, other threads:[~2020-03-10 19:38 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-06  8:10 [PATCH] ftrace: return first found result in lookup_rec() Artem Savkov
2020-03-06 17:12 ` Steven Rostedt
2020-03-06 17:43   ` [PATCH v2] " Artem Savkov
2020-03-10 19:38     ` Steven Rostedt

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).