Live Patching
 help / color / mirror / Atom feed
From: Joe Lawrence <joe.lawrence@redhat.com>
To: Puranjay Mohan <puranjay@kernel.org>
Cc: live-patching@vger.kernel.org,
	Josh Poimboeuf <jpoimboe@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>, Song Liu <song@kernel.org>,
	Miroslav Benes <mbenes@suse.cz>
Subject: Re: [PATCH 2/3] objtool/klp: Reject changed functions without an ftrace call site
Date: Thu, 22 Oct 2026 11:55:48 -0400	[thread overview]
Message-ID: <atoyBMUFX98mr-Uw@redhat.com> (raw)
In-Reply-To: <20261022122544.125305-3-puranjay@kernel.org>

On Thu, Oct 22, 2026 at 05:25:37AM -0700, Puranjay Mohan wrote:
> Livepatch redirects a function through its ftrace call site.  If a
> changed function doesn't have one, klp-build succeeds but the patch
> module fails to load:
> 
>   livepatch: failed to find location for function 'nsproxy_free'
>   livepatch: failed to patch object 'vmlinux'
>   livepatch: failed to enable patch 'livepatch_nsproxy'
> 
> This is easy to hit because the kernel's 'inline' implies notrace, so
> any inline function which the compiler emits out of line can't be
> patched.
> 
> Make klp diff fail for any changed function which has no __mcount_loc
> entry in the original object.
> 
> Signed-off-by: Puranjay Mohan <puranjay@kernel.org>
> ---
>  tools/objtool/include/objtool/elf.h |  1 +
>  tools/objtool/klp-diff.c            | 47 +++++++++++++++++++++++++++++
>  2 files changed, 48 insertions(+)
> 
> diff --git a/tools/objtool/include/objtool/elf.h b/tools/objtool/include/objtool/elf.h
> index a82517a76a0f6..f7e6a652ee788 100644
> --- a/tools/objtool/include/objtool/elf.h
> +++ b/tools/objtool/include/objtool/elf.h
> @@ -98,6 +98,7 @@ struct symbol {
>  	u8 klp		     : 1;
>  	u8 dont_correlate    : 1;
>  	u8 fake		     : 1;
> +	u8 traceable	     : 1;
>  	struct list_head pv_target;
>  	struct reloc *relocs;
>  	struct section *group_sec;
> diff --git a/tools/objtool/klp-diff.c b/tools/objtool/klp-diff.c
> index 34da55e456097..f8659950ec9a9 100644
> --- a/tools/objtool/klp-diff.c
> +++ b/tools/objtool/klp-diff.c
> @@ -1098,6 +1098,50 @@ static int mark_changed_functions(struct elfs *e)
>  	return !changed ? 1 : 0;
>  }
>  
> +/*
> + * Like ftrace_location(), accept an ftrace call site anywhere in the function.
> + */
> +static void mark_traceable_functions(struct elf *elf)
> +{
> +	struct section *sec;
> +	struct reloc *reloc;
> +
> +	sec = find_section_by_name(elf, "__mcount_loc");
> +	if (!sec || !sec->rsec)
> +		return;
> +
> +	for_each_reloc(sec->rsec, reloc) {
> +		struct symbol *func;
> +
> +		func = find_func_containing(reloc->sym->sec,
> +					    reloc->sym->offset + reloc_addend(reloc));
> +		if (func)
> +			func->traceable = 1;
> +	}
> +}
> +
> +/*
> + * Livepatch redirects functions through their ftrace call sites, so a function
> + * without one can't be patched.
> + */
> +static int validate_traceable_functions(struct elfs *e)
> +{
> +	struct symbol *patched_sym;
> +	bool error = false;
> +
> +	mark_traceable_functions(e->orig);
> +
> +	for_each_sym(e->patched, patched_sym) {
> +		if (!patched_sym->changed || patched_sym->twin->traceable)
> +			continue;
> +
> +		ERROR("%s: no ftrace call site, can't patch", patched_sym->twin->name);
> +		error = true;
> +	}
> +
> +	return error ? -1 : 0;
> +}
> +
>  static int clone_included_functions(struct elfs *e)
>  {
>  	struct symbol *patched_sym;
> @@ -2260,6 +2304,9 @@ int cmd_klp_diff(int argc, const char **argv)
>  	if (ret > 0)
>  		return 0;
>  
> +	if (validate_traceable_functions(&e))
> +		return -1;
> +
>  	e.out = elf_create_file(&e.orig->ehdr, argv[2]);
>  	if (!e.out)
>  		return -1;
> -- 
> 2.53.0-Meta
> 
>

 
Acked-by: Joe Lawrence <joe.lawrence@redhat.com>

--
Joe


  reply	other threads:[~2026-10-22 15:55 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-22 12:25 [PATCH 0/3] objtool/klp: Reject changed functions without an ftrace call site Puranjay Mohan
2026-10-22 12:25 ` [PATCH 1/3] objtool/klp: Build test fixtures with ftrace Puranjay Mohan
2026-10-22 14:46   ` Joe Lawrence
2026-10-22 16:43     ` Puranjay Mohan
2026-10-22 12:25 ` [PATCH 2/3] objtool/klp: Reject changed functions without an ftrace call site Puranjay Mohan
2026-10-22 15:55   ` Joe Lawrence [this message]
2026-10-22 12:25 ` [PATCH 3/3] objtool/klp: Add test for " Puranjay Mohan
2026-10-22 16:02   ` Joe Lawrence

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=atoyBMUFX98mr-Uw@redhat.com \
    --to=joe.lawrence@redhat.com \
    --cc=jpoimboe@kernel.org \
    --cc=live-patching@vger.kernel.org \
    --cc=mbenes@suse.cz \
    --cc=peterz@infradead.org \
    --cc=puranjay@kernel.org \
    --cc=song@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox