linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] arm64: ftrace: fix building without CONFIG_MODULES
@ 2017-06-09 10:27 Arnd Bergmann
  2017-06-09 11:38 ` Will Deacon
  0 siblings, 1 reply; 6+ messages in thread
From: Arnd Bergmann @ 2017-06-09 10:27 UTC (permalink / raw)
  To: linux-arm-kernel

When CONFIG_MODULES is disabled, we cannot dereference a module pointer:

arch/arm64/kernel/ftrace.c: In function 'ftrace_make_call':
arch/arm64/kernel/ftrace.c:107:36: error: dereferencing pointer to incomplete type 'struct module'
   trampoline = (unsigned long *)mod->arch.ftrace_trampoline;

Also, the within_module() function is not defined:

arch/arm64/kernel/ftrace.c: In function 'ftrace_make_nop':
arch/arm64/kernel/ftrace.c:171:8: error: implicit declaration of function 'within_module'; did you mean 'init_module'? [-Werror=implicit-function-declaration]

This addresses both by adding the appropriate stubs.

Fixes: e71a4e1bebaf ("arm64: ftrace: add support for far branches to dynamic ftrace")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 arch/arm64/include/asm/module.h | 6 ++++++
 arch/arm64/kernel/ftrace.c      | 2 +-
 include/linux/module.h          | 5 +++++
 3 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/arch/arm64/include/asm/module.h b/arch/arm64/include/asm/module.h
index 19bd97671bb8..ca5d024f4247 100644
--- a/arch/arm64/include/asm/module.h
+++ b/arch/arm64/include/asm/module.h
@@ -36,6 +36,12 @@ struct mod_arch_specific {
 };
 #endif
 
+#if defined(CONFIG_MODULES) && defined(CONFIG_ARM64_MODULE_PLTS)
+#define module_ftrace_trampoline(mod) ((mod)->arch.ftrace_trampoline)
+#else
+#define module_ftrace_trampoline(mod) NULL
+#endif
+
 u64 module_emit_plt_entry(struct module *mod, void *loc, const Elf64_Rela *rela,
 			  Elf64_Sym *sym);
 
diff --git a/arch/arm64/kernel/ftrace.c b/arch/arm64/kernel/ftrace.c
index 8a42be0693c9..7f5eb9939a55 100644
--- a/arch/arm64/kernel/ftrace.c
+++ b/arch/arm64/kernel/ftrace.c
@@ -104,7 +104,7 @@ int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr)
 		 * is added in the future, but for now, the pr_err() below
 		 * deals with a theoretical issue only.
 		 */
-		trampoline = (unsigned long *)mod->arch.ftrace_trampoline;
+		trampoline = module_ftrace_trampoline(mod);
 		if (trampoline[0] != addr) {
 			if (trampoline[0] != 0) {
 				pr_err("ftrace: far branches to multiple entry points unsupported inside a single module\n");
diff --git a/include/linux/module.h b/include/linux/module.h
index 21f56393602f..9196f532f158 100644
--- a/include/linux/module.h
+++ b/include/linux/module.h
@@ -671,6 +671,11 @@ static inline bool is_module_text_address(unsigned long addr)
 	return false;
 }
 
+static inline bool within_module(unsigned long addr, const struct module *mod)
+{
+	return false;
+}
+
 /* Get/put a kernel symbol (calls should be symmetric) */
 #define symbol_get(x) ({ extern typeof(x) x __attribute__((weak)); &(x); })
 #define symbol_put(x) do { } while (0)
-- 
2.9.0

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

* [PATCH] arm64: ftrace: fix building without CONFIG_MODULES
  2017-06-09 10:27 [PATCH] arm64: ftrace: fix building without CONFIG_MODULES Arnd Bergmann
@ 2017-06-09 11:38 ` Will Deacon
  2017-06-09 18:57   ` Arnd Bergmann
  0 siblings, 1 reply; 6+ messages in thread
From: Will Deacon @ 2017-06-09 11:38 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Arnd,

On Fri, Jun 09, 2017 at 12:27:06PM +0200, Arnd Bergmann wrote:
> When CONFIG_MODULES is disabled, we cannot dereference a module pointer:
> 
> arch/arm64/kernel/ftrace.c: In function 'ftrace_make_call':
> arch/arm64/kernel/ftrace.c:107:36: error: dereferencing pointer to incomplete type 'struct module'
>    trampoline = (unsigned long *)mod->arch.ftrace_trampoline;
> 
> Also, the within_module() function is not defined:
> 
> arch/arm64/kernel/ftrace.c: In function 'ftrace_make_nop':
> arch/arm64/kernel/ftrace.c:171:8: error: implicit declaration of function 'within_module'; did you mean 'init_module'? [-Werror=implicit-function-declaration]
> 
> This addresses both by adding the appropriate stubs.
> 
> Fixes: e71a4e1bebaf ("arm64: ftrace: add support for far branches to dynamic ftrace")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  arch/arm64/include/asm/module.h | 6 ++++++
>  arch/arm64/kernel/ftrace.c      | 2 +-
>  include/linux/module.h          | 5 +++++
>  3 files changed, 12 insertions(+), 1 deletion(-)

I can't seem to reproduce this simply by disabling MODULES in defconfig.
Could you share your .config, please?

Will

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

* [PATCH] arm64: ftrace: fix building without CONFIG_MODULES
  2017-06-09 11:38 ` Will Deacon
@ 2017-06-09 18:57   ` Arnd Bergmann
  2017-06-12 12:48     ` Will Deacon
  0 siblings, 1 reply; 6+ messages in thread
From: Arnd Bergmann @ 2017-06-09 18:57 UTC (permalink / raw)
  To: linux-arm-kernel

On Fri, Jun 9, 2017 at 1:38 PM, Will Deacon <will.deacon@arm.com> wrote:
> Hi Arnd,
>
> On Fri, Jun 09, 2017 at 12:27:06PM +0200, Arnd Bergmann wrote:
>> When CONFIG_MODULES is disabled, we cannot dereference a module pointer:
>>
>> arch/arm64/kernel/ftrace.c: In function 'ftrace_make_call':
>> arch/arm64/kernel/ftrace.c:107:36: error: dereferencing pointer to incomplete type 'struct module'
>>    trampoline = (unsigned long *)mod->arch.ftrace_trampoline;
>>
>> Also, the within_module() function is not defined:
>>
>> arch/arm64/kernel/ftrace.c: In function 'ftrace_make_nop':
>> arch/arm64/kernel/ftrace.c:171:8: error: implicit declaration of function 'within_module'; did you mean 'init_module'? [-Werror=implicit-function-declaration]
>>
>> This addresses both by adding the appropriate stubs.
>>
>> Fixes: e71a4e1bebaf ("arm64: ftrace: add support for far branches to dynamic ftrace")
>> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
>> ---
>>  arch/arm64/include/asm/module.h | 6 ++++++
>>  arch/arm64/kernel/ftrace.c      | 2 +-
>>  include/linux/module.h          | 5 +++++
>>  3 files changed, 12 insertions(+), 1 deletion(-)
>
> I can't seem to reproduce this simply by disabling MODULES in defconfig.
> Could you share your .config, please?

This is the randconfig I used: https://pastebin.com/SfKBY7f8

      Arnd

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

* [PATCH] arm64: ftrace: fix building without CONFIG_MODULES
  2017-06-09 18:57   ` Arnd Bergmann
@ 2017-06-12 12:48     ` Will Deacon
  2017-06-12 13:01       ` Ard Biesheuvel
  2017-06-12 14:22       ` Arnd Bergmann
  0 siblings, 2 replies; 6+ messages in thread
From: Will Deacon @ 2017-06-12 12:48 UTC (permalink / raw)
  To: linux-arm-kernel

On Fri, Jun 09, 2017 at 08:57:31PM +0200, Arnd Bergmann wrote:
> On Fri, Jun 9, 2017 at 1:38 PM, Will Deacon <will.deacon@arm.com> wrote:
> > On Fri, Jun 09, 2017 at 12:27:06PM +0200, Arnd Bergmann wrote:
> >> When CONFIG_MODULES is disabled, we cannot dereference a module pointer:
> >>
> >> arch/arm64/kernel/ftrace.c: In function 'ftrace_make_call':
> >> arch/arm64/kernel/ftrace.c:107:36: error: dereferencing pointer to incomplete type 'struct module'
> >>    trampoline = (unsigned long *)mod->arch.ftrace_trampoline;
> >>
> >> Also, the within_module() function is not defined:
> >>
> >> arch/arm64/kernel/ftrace.c: In function 'ftrace_make_nop':
> >> arch/arm64/kernel/ftrace.c:171:8: error: implicit declaration of function 'within_module'; did you mean 'init_module'? [-Werror=implicit-function-declaration]
> >>
> >> This addresses both by adding the appropriate stubs.
> >>
> >> Fixes: e71a4e1bebaf ("arm64: ftrace: add support for far branches to dynamic ftrace")
> >> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> >> ---
> >>  arch/arm64/include/asm/module.h | 6 ++++++
> >>  arch/arm64/kernel/ftrace.c      | 2 +-
> >>  include/linux/module.h          | 5 +++++
> >>  3 files changed, 12 insertions(+), 1 deletion(-)
> >
> > I can't seem to reproduce this simply by disabling MODULES in defconfig.
> > Could you share your .config, please?
> 
> This is the randconfig I used: https://pastebin.com/SfKBY7f8

Thanks, I was forgetting to enable ftrace. I think a simpler patch (and one
that I can just apply via arm64) is switching the IS_ENABLEDs out for
#ifdefs. See below.

Will

--->8

diff --git a/arch/arm64/kernel/ftrace.c b/arch/arm64/kernel/ftrace.c
index 8a42be0693c9..401aa27808a4 100644
--- a/arch/arm64/kernel/ftrace.c
+++ b/arch/arm64/kernel/ftrace.c
@@ -71,11 +71,12 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
 int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr)
 {
 	unsigned long pc = rec->ip;
-	long offset = (long)pc - (long)addr;
 	u32 old, new;
 
-	if (IS_ENABLED(CONFIG_ARM64_MODULE_PLTS) &&
-	    (offset < -SZ_128M || offset >= SZ_128M)) {
+#ifdef CONFIG_ARM64_MODULE_PLTS
+	long offset = (long)pc - (long)addr;
+
+	if (offset < -SZ_128M || offset >= SZ_128M) {
 		unsigned long *trampoline;
 		struct module *mod;
 
@@ -121,6 +122,7 @@ int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr)
 		}
 		addr = (unsigned long)&trampoline[1];
 	}
+#endif /* CONFIG_ARM64_MODULE_PLTS */
 
 	old = aarch64_insn_gen_nop();
 	new = aarch64_insn_gen_branch_imm(pc, addr, AARCH64_INSN_BRANCH_LINK);
@@ -135,12 +137,13 @@ int ftrace_make_nop(struct module *mod, struct dyn_ftrace *rec,
 		    unsigned long addr)
 {
 	unsigned long pc = rec->ip;
-	long offset = (long)pc - (long)addr;
 	bool validate = true;
 	u32 old = 0, new;
 
-	if (IS_ENABLED(CONFIG_ARM64_MODULE_PLTS) &&
-	    (offset < -SZ_128M || offset >= SZ_128M)) {
+#ifdef CONFIG_ARM64_MODULE_PLTS
+	long offset = (long)pc - (long)addr;
+
+	if (offset < -SZ_128M || offset >= SZ_128M) {
 		u32 replaced;
 
 		/*
@@ -177,6 +180,7 @@ int ftrace_make_nop(struct module *mod, struct dyn_ftrace *rec,
 		old = aarch64_insn_gen_branch_imm(pc, addr,
 						  AARCH64_INSN_BRANCH_LINK);
 	}
+#endif /* CONFIG_ARM64_MODULE_PLTS */
 
 	new = aarch64_insn_gen_nop();
 

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

* [PATCH] arm64: ftrace: fix building without CONFIG_MODULES
  2017-06-12 12:48     ` Will Deacon
@ 2017-06-12 13:01       ` Ard Biesheuvel
  2017-06-12 14:22       ` Arnd Bergmann
  1 sibling, 0 replies; 6+ messages in thread
From: Ard Biesheuvel @ 2017-06-12 13:01 UTC (permalink / raw)
  To: linux-arm-kernel

On 12 June 2017 at 14:48, Will Deacon <will.deacon@arm.com> wrote:
> On Fri, Jun 09, 2017 at 08:57:31PM +0200, Arnd Bergmann wrote:
>> On Fri, Jun 9, 2017 at 1:38 PM, Will Deacon <will.deacon@arm.com> wrote:
>> > On Fri, Jun 09, 2017 at 12:27:06PM +0200, Arnd Bergmann wrote:
>> >> When CONFIG_MODULES is disabled, we cannot dereference a module pointer:
>> >>
>> >> arch/arm64/kernel/ftrace.c: In function 'ftrace_make_call':
>> >> arch/arm64/kernel/ftrace.c:107:36: error: dereferencing pointer to incomplete type 'struct module'
>> >>    trampoline = (unsigned long *)mod->arch.ftrace_trampoline;
>> >>
>> >> Also, the within_module() function is not defined:
>> >>
>> >> arch/arm64/kernel/ftrace.c: In function 'ftrace_make_nop':
>> >> arch/arm64/kernel/ftrace.c:171:8: error: implicit declaration of function 'within_module'; did you mean 'init_module'? [-Werror=implicit-function-declaration]
>> >>
>> >> This addresses both by adding the appropriate stubs.
>> >>
>> >> Fixes: e71a4e1bebaf ("arm64: ftrace: add support for far branches to dynamic ftrace")
>> >> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
>> >> ---
>> >>  arch/arm64/include/asm/module.h | 6 ++++++
>> >>  arch/arm64/kernel/ftrace.c      | 2 +-
>> >>  include/linux/module.h          | 5 +++++
>> >>  3 files changed, 12 insertions(+), 1 deletion(-)
>> >
>> > I can't seem to reproduce this simply by disabling MODULES in defconfig.
>> > Could you share your .config, please?
>>
>> This is the randconfig I used: https://pastebin.com/SfKBY7f8
>
> Thanks, I was forgetting to enable ftrace. I think a simpler patch (and one
> that I can just apply via arm64) is switching the IS_ENABLEDs out for
> #ifdefs.

I agree that this makes more sense in this particular case.

Acked-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>

Interestingly, ARM64_MODULE_PLTS does not depend on CONFIG_MODULES,
but I can't remember whether that was deliberate or an oversight.

> See below.
>
> --->8
>
> diff --git a/arch/arm64/kernel/ftrace.c b/arch/arm64/kernel/ftrace.c
> index 8a42be0693c9..401aa27808a4 100644
> --- a/arch/arm64/kernel/ftrace.c
> +++ b/arch/arm64/kernel/ftrace.c
> @@ -71,11 +71,12 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
>  int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr)
>  {
>         unsigned long pc = rec->ip;
> -       long offset = (long)pc - (long)addr;
>         u32 old, new;
>
> -       if (IS_ENABLED(CONFIG_ARM64_MODULE_PLTS) &&
> -           (offset < -SZ_128M || offset >= SZ_128M)) {
> +#ifdef CONFIG_ARM64_MODULE_PLTS
> +       long offset = (long)pc - (long)addr;
> +
> +       if (offset < -SZ_128M || offset >= SZ_128M) {
>                 unsigned long *trampoline;
>                 struct module *mod;
>
> @@ -121,6 +122,7 @@ int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr)
>                 }
>                 addr = (unsigned long)&trampoline[1];
>         }
> +#endif /* CONFIG_ARM64_MODULE_PLTS */
>
>         old = aarch64_insn_gen_nop();
>         new = aarch64_insn_gen_branch_imm(pc, addr, AARCH64_INSN_BRANCH_LINK);
> @@ -135,12 +137,13 @@ int ftrace_make_nop(struct module *mod, struct dyn_ftrace *rec,
>                     unsigned long addr)
>  {
>         unsigned long pc = rec->ip;
> -       long offset = (long)pc - (long)addr;
>         bool validate = true;
>         u32 old = 0, new;
>
> -       if (IS_ENABLED(CONFIG_ARM64_MODULE_PLTS) &&
> -           (offset < -SZ_128M || offset >= SZ_128M)) {
> +#ifdef CONFIG_ARM64_MODULE_PLTS
> +       long offset = (long)pc - (long)addr;
> +
> +       if (offset < -SZ_128M || offset >= SZ_128M) {
>                 u32 replaced;
>
>                 /*
> @@ -177,6 +180,7 @@ int ftrace_make_nop(struct module *mod, struct dyn_ftrace *rec,
>                 old = aarch64_insn_gen_branch_imm(pc, addr,
>                                                   AARCH64_INSN_BRANCH_LINK);
>         }
> +#endif /* CONFIG_ARM64_MODULE_PLTS */
>
>         new = aarch64_insn_gen_nop();
>

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

* [PATCH] arm64: ftrace: fix building without CONFIG_MODULES
  2017-06-12 12:48     ` Will Deacon
  2017-06-12 13:01       ` Ard Biesheuvel
@ 2017-06-12 14:22       ` Arnd Bergmann
  1 sibling, 0 replies; 6+ messages in thread
From: Arnd Bergmann @ 2017-06-12 14:22 UTC (permalink / raw)
  To: linux-arm-kernel

On Mon, Jun 12, 2017 at 2:48 PM, Will Deacon <will.deacon@arm.com> wrote:
> On Fri, Jun 09, 2017 at 08:57:31PM +0200, Arnd Bergmann wrote:
>> On Fri, Jun 9, 2017 at 1:38 PM, Will Deacon <will.deacon@arm.com> wrote:
>> > I can't seem to reproduce this simply by disabling MODULES in defconfig.
>> > Could you share your .config, please?
>>
>> This is the randconfig I used: https://pastebin.com/SfKBY7f8
>
> Thanks, I was forgetting to enable ftrace. I think a simpler patch (and one
> that I can just apply via arm64) is switching the IS_ENABLEDs out for
> #ifdefs. See below.

Yes, good idea.

        Arnd

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

end of thread, other threads:[~2017-06-12 14:22 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-06-09 10:27 [PATCH] arm64: ftrace: fix building without CONFIG_MODULES Arnd Bergmann
2017-06-09 11:38 ` Will Deacon
2017-06-09 18:57   ` Arnd Bergmann
2017-06-12 12:48     ` Will Deacon
2017-06-12 13:01       ` Ard Biesheuvel
2017-06-12 14:22       ` Arnd Bergmann

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