recordmcount: only record relocation of type R_AARCH64_CALL26 on arm64.
PATCH 1/1 recordmcount: only record relocation of type R_AARCH64_CALL26 on arm64.
From: Gregory Herrero <[email protected]>
Currently, if a section has a relocation to '_mcount' symbol, a new __mcount_loc entry will be added whatever the relocation type is. This is problematic when a relocation to '_mcount' is in the middle of a section and is not a call for ftrace use.
Such relocation could be generated with below code for example:
bool is_mcount(unsigned long addr)
{
return (target == (unsigned long) &_mcount);
}With this snippet of code, ftrace will try to patch the mcount location generated by this code on module load and fail with:
Call trace:
ftrace_bug+0xa0/0x28c
ftrace_process_locs+0x2f4/0x430
ftrace_module_init+0x30/0x38
load_module+0x14f0/0x1e78
__do_sys_finit_module+0x100/0x11c
__arm64_sys_finit_module+0x28/0x34
el0_svc_common+0x88/0x194
el0_svc_handler+0x38/0x8c
el0_svc+0x8/0xc
---[ end trace d828d06b36ad9d59 ]---
ftrace failed to modify
[<ffffa2dbf3a3a41c>] 0xffffa2dbf3a3a41c
actual: 66:a9:3c:90
Initializing ftrace call sites
ftrace record flags: 2000000
(0)
expected tramp: ffffa2dc6cf66724So Limit the relocation type to R_AARCH64_CALL26 as in perl version of recordmcount.
--- scripts/recordmcount.c | 6 ++++++ 1 file changed, 6 insertions(+)
scripts/recordmcount.c +6 -0
@@ -434,6 +434,11 @@ static int arm_is_fake_mcount(Elf32_Rel const *rp)return 1 ; } +static int arm64_is_fake_mcount (Elf64_Rel const *rp) +{ +return ELF64_R_TYPE (w (rp->r_info)) !=R_AARCH64_CALL26 ; +} +/* 64-bit EM_MIPS has weird ELF64_Rela.r_info. * http://techpubs.sgi.com/library/manuals/4000/007-4658-001/pdf/007-4658-001.pdf * We interpret Table 29 Relocation Operation (Elf64_Rel, Elf64_Rela) [p.40]
@@ -547,6 +552,7 @@ static int do_file(char const *const fname) make_nop = make_nop_arm64; rel_type_nop =R_AARCH64_NONE ; ideal_nop = ideal_nop4_arm64; + is_fake_mcount64 = arm64_is_fake_mcount;break ;case EM_IA_64 : reltype =R_IA64_IMM64 ;break ;case EM_MIPS :/* reltype: e_class */ break ;
Signature · 1 line
2.27.0
Greg KH
maintainerQuoted 71 lines · On Fri, Jul 17, 2020 at 04:33:38PM +0200, [email protected] wrote:
From: Gregory Herrero <[email protected]>
Currently, if a section has a relocation to '
_mcount' symbol, a new__mcount_locentry will be added whatever the relocation type is. This is problematic when a relocation to '_mcount' is in the middle of a section and is not a call for ftrace use.Such relocation could be generated with below code for example:
bool is_mcount(unsigned long addr) { return (target == (unsigned long) &_mcount); }With this snippet of code, ftrace will try to patch the mcount location generated by this code on module load and fail with:
Call trace: ftrace_bug+0xa0/0x28c ftrace_process_locs+0x2f4/0x430 ftrace_module_init+0x30/0x38 load_module+0x14f0/0x1e78 __do_sys_finit_module+0x100/0x11c __arm64_sys_finit_module+0x28/0x34 el0_svc_common+0x88/0x194 el0_svc_handler+0x38/0x8c el0_svc+0x8/0xc ---[ end trace d828d06b36ad9d59 ]--- ftrace failed to modify [<ffffa2dbf3a3a41c>] 0xffffa2dbf3a3a41c actual: 66:a9:3c:90 Initializing ftrace call sites ftrace record flags: 2000000 (0) expected tramp: ffffa2dc6cf66724So Limit the relocation type to
R_AARCH64_CALL26as in perl version of recordmcount.Fixes ed60453fa8f8 ("ARM: 6511/1: ftrace: add ARM support for C version of recordmcount")Signed-off-by Gregory Herrero <[email protected]>--- scripts/recordmcount.c | 6 ++++++ 1 file changed, 6 insertions(+)scripts/recordmcount.c +6
-0@@ -434,6 +434,11 @@ static int arm_is_fake_mcount(Elf32_Rel const *rp)return 1 ; } +static int arm64_is_fake_mcount (Elf64_Rel const *rp) +{ +return ELF64_R_TYPE (w (rp->r_info)) !=R_AARCH64_CALL26 ; +} +/* 64-bit EM_MIPS has weird ELF64_Rela.r_info. * http://techpubs.sgi.com/library/manuals/4000/007-4658-001/pdf/007-4658-001.pdf * We interpret Table 29 Relocation Operation (Elf64_Rel, Elf64_Rela) [p.40] @@ -547,6 +552,7 @@ static int do_file(char const *const fname) make_nop = make_nop_arm64; rel_type_nop =R_AARCH64_NONE ; ideal_nop = ideal_nop4_arm64; + is_fake_mcount64 = arm64_is_fake_mcount;break ;case EM_IA_64 : reltype =R_IA64_IMM64 ;break ;case EM_MIPS :/* reltype: e_class */ break ;Signature · 1 line
2.27.0
<formletter>
This is not the correct way to submit patches for inclusion in the stable kernel tree. Please read:
https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html
for how to do this properly.
</formletter>
Quoted 35 lines · On Fri, 17 Jul 2020 16:33:38 +0200 [email protected] wrote:
From: Gregory Herrero <[email protected]>
Currently, if a section has a relocation to '
_mcount' symbol, a new__mcount_locentry will be added whatever the relocation type is. This is problematic when a relocation to '_mcount' is in the middle of a section and is not a call for ftrace use.Such relocation could be generated with below code for example:
bool is_mcount(unsigned long addr) { return (target == (unsigned long) &_mcount); }With this snippet of code, ftrace will try to patch the mcount location generated by this code on module load and fail with:
Call trace: ftrace_bug+0xa0/0x28c ftrace_process_locs+0x2f4/0x430 ftrace_module_init+0x30/0x38 load_module+0x14f0/0x1e78 __do_sys_finit_module+0x100/0x11c __arm64_sys_finit_module+0x28/0x34 el0_svc_common+0x88/0x194 el0_svc_handler+0x38/0x8c el0_svc+0x8/0xc ---[ end trace d828d06b36ad9d59 ]--- ftrace failed to modify [<ffffa2dbf3a3a41c>] 0xffffa2dbf3a3a41c actual: 66:a9:3c:90 Initializing ftrace call sites ftrace record flags: 2000000 (0) expected tramp: ffffa2dc6cf66724
Quoted 3 lines
So Limit the relocation type to
R_AARCH64_CALL26as in perl version of recordmcount.
I'd rather have this go through the arm64 tree, as they can test it better than I can.
-- Steve
Quoted 30 lines
Fixes ed60453fa8f8 ("ARM: 6511/1: ftrace: add ARM support for C version of recordmcount")Signed-off-by Gregory Herrero <[email protected]>--- scripts/recordmcount.c | 6 ++++++ 1 file changed, 6 insertions(+)scripts/recordmcount.c +6
-0@@ -434,6 +434,11 @@ static int arm_is_fake_mcount(Elf32_Rel const *rp)return 1 ; } +static int arm64_is_fake_mcount (Elf64_Rel const *rp) +{ +return ELF64_R_TYPE (w (rp->r_info)) !=R_AARCH64_CALL26 ; +} +/* 64-bit EM_MIPS has weird ELF64_Rela.r_info. * http://techpubs.sgi.com/library/manuals/4000/007-4658-001/pdf/007-4658-001.pdf * We interpret Table 29 Relocation Operation (Elf64_Rel, Elf64_Rela) [p.40] @@ -547,6 +552,7 @@ static int do_file(char const *const fname) make_nop = make_nop_arm64; rel_type_nop =R_AARCH64_NONE ; ideal_nop = ideal_nop4_arm64; + is_fake_mcount64 = arm64_is_fake_mcount;break ;case EM_IA_64 : reltype =R_IA64_IMM64 ;break ;case EM_MIPS :/* reltype: e_class */ break ;
Quoted 42 lines · Steven Rostedt
Quoted 35 lines · On Fri, 17 Jul 2020 16:33:38 +0200 [email protected] wrote:
From: Gregory Herrero <[email protected]>
Currently, if a section has a relocation to '
_mcount' symbol, a new__mcount_locentry will be added whatever the relocation type is. This is problematic when a relocation to '_mcount' is in the middle of a section and is not a call for ftrace use.Such relocation could be generated with below code for example:
bool is_mcount(unsigned long addr) { return (target == (unsigned long) &_mcount); }With this snippet of code, ftrace will try to patch the mcount location generated by this code on module load and fail with:
Call trace: ftrace_bug+0xa0/0x28c ftrace_process_locs+0x2f4/0x430 ftrace_module_init+0x30/0x38 load_module+0x14f0/0x1e78 __do_sys_finit_module+0x100/0x11c __arm64_sys_finit_module+0x28/0x34 el0_svc_common+0x88/0x194 el0_svc_handler+0x38/0x8c el0_svc+0x8/0xc ---[ end trace d828d06b36ad9d59 ]--- ftrace failed to modify [<ffffa2dbf3a3a41c>] 0xffffa2dbf3a3a41c actual: 66:a9:3c:90 Initializing ftrace call sites ftrace record flags: 2000000 (0) expected tramp: ffffa2dc6cf66724Quoted 3 lines
So Limit the relocation type to
R_AARCH64_CALL26as in perl version of recordmcount.
Quoted 7 lines
I'd rather have this go through the arm64 tree, as they can test it better than I can.
-- Steve
Thanks Steve.
Should I send a V2 to add 'Cc: [email protected]' in the commit description or can someone take care of it when adding the commit to the tree?
Thanks,
Greg
Quoted 32 lines
Quoted 31 lines
Fixes ed60453fa8f8 ("ARM: 6511/1: ftrace: add ARM support for C version of recordmcount")Signed-off-by Gregory Herrero <[email protected]>--- scripts/recordmcount.c | 6 ++++++ 1 file changed, 6 insertions(+)scripts/recordmcount.c +6
-0@@ -434,6 +434,11 @@ static int arm_is_fake_mcount(Elf32_Rel const *rp)return 1 ; } +static int arm64_is_fake_mcount (Elf64_Rel const *rp) +{ +return ELF64_R_TYPE (w (rp->r_info)) !=R_AARCH64_CALL26 ; +} +/* 64-bit EM_MIPS has weird ELF64_Rela.r_info. * http://techpubs.sgi.com/library/manuals/4000/007-4658-001/pdf/007-4658-001.pdf * We interpret Table 29 Relocation Operation (Elf64_Rel, Elf64_Rela) [p.40] @@ -547,6 +552,7 @@ static int do_file(char const *const fname) make_nop = make_nop_arm64; rel_type_nop =R_AARCH64_NONE ; ideal_nop = ideal_nop4_arm64; + is_fake_mcount64 = arm64_is_fake_mcount;break ;case EM_IA_64 : reltype =R_IA64_IMM64 ;break ;case EM_MIPS :/* reltype: e_class */ break ;
Quoted 4 lines · On Fri, 17 Jul 2020 22:01:19 +0200 Gregory Herrero…
Thanks Steve.
Should I send a V2 to add 'Cc: [email protected]' in the commit description or can someone take care of it when adding the commit to the tree?
If I was taking it, I would simply add the Cc: [email protected] to the commit log, and no resend would be needed.
It's up to the ARM64 maintainers to decide in this case.
Cheers,
-- Steve
Quoted 36 lines · Steven Rostedt
Quoted 34 lines · On Fri, 17 Jul 2020 16:33:38 +0200 [email protected] wrote:
From: Gregory Herrero <[email protected]> Currently, if a section has a relocation to '
_mcount' symbol, a new__mcount_locentry will be added whatever the relocation type is. This is problematic when a relocation to '_mcount' is in the middle of a section and is not a call for ftrace use.Such relocation could be generated with below code for example:
bool is_mcount(unsigned long addr) { return (target == (unsigned long) &_mcount); }With this snippet of code, ftrace will try to patch the mcount location generated by this code on module load and fail with:
Call trace: ftrace_bug+0xa0/0x28c ftrace_process_locs+0x2f4/0x430 ftrace_module_init+0x30/0x38 load_module+0x14f0/0x1e78 __do_sys_finit_module+0x100/0x11c __arm64_sys_finit_module+0x28/0x34 el0_svc_common+0x88/0x194 el0_svc_handler+0x38/0x8c el0_svc+0x8/0xc ---[ end trace d828d06b36ad9d59 ]--- ftrace failed to modify [<ffffa2dbf3a3a41c>] 0xffffa2dbf3a3a41c actual: 66:a9:3c:90 Initializing ftrace call sites ftrace record flags: 2000000 (0) expected tramp: ffffa2dc6cf66724
Quoted 7 lines
Quoted 2 lines
So Limit the relocation type to
R_AARCH64_CALL26as in perl version of recordmcount.I'd rather have this go through the arm64 tree, as they can test it better than I can.
Thanks Steve.
Quoted 1 line
Quoted 1 line
Fixes ed60453fa8f8 ("ARM: 6511/1: ftrace: add ARM support for C version of recordmcount")
This Fixes tag looks wrong. The above commit was for arm32.
Signature · 1 line
Catalin
Quoted 43 lines · Catalin Marinas
Quoted 42 lines · Steven Rostedt
Quoted 34 lines · On Fri, 17 Jul 2020 16:33:38 +0200 [email protected] wrote:
From: Gregory Herrero <[email protected]> Currently, if a section has a relocation to '
_mcount' symbol, a new__mcount_locentry will be added whatever the relocation type is. This is problematic when a relocation to '_mcount' is in the middle of a section and is not a call for ftrace use.Such relocation could be generated with below code for example:
bool is_mcount(unsigned long addr) { return (target == (unsigned long) &_mcount); }With this snippet of code, ftrace will try to patch the mcount location generated by this code on module load and fail with:
Call trace: ftrace_bug+0xa0/0x28c ftrace_process_locs+0x2f4/0x430 ftrace_module_init+0x30/0x38 load_module+0x14f0/0x1e78 __do_sys_finit_module+0x100/0x11c __arm64_sys_finit_module+0x28/0x34 el0_svc_common+0x88/0x194 el0_svc_handler+0x38/0x8c el0_svc+0x8/0xc ---[ end trace d828d06b36ad9d59 ]--- ftrace failed to modify [<ffffa2dbf3a3a41c>] 0xffffa2dbf3a3a41c actual: 66:a9:3c:90 Initializing ftrace call sites ftrace record flags: 2000000 (0) expected tramp: ffffa2dc6cf66724Quoted 2 lines
So Limit the relocation type to
R_AARCH64_CALL26as in perl version of recordmcount.I'd rather have this go through the arm64 tree, as they can test it better than I can.
Quoted 8 lines
Quoted 1 line
Thanks Steve.
Quoted 1 line
Quoted 1 line
Fixes ed60453fa8f8 ("ARM: 6511/1: ftrace: add ARM support for C version of recordmcount")This Fixes tag looks wrong. The above commit was for arm32.
Thanks for catching this.
It should be as below instead:
Should I send a V2?
Thanks,
Greg
Hi Gregory,
As a general thing, for patches affecting arm64 could you please Cc the linx-arm-kernel mailing list ([email protected]). Some folk working on arm/arm64 aren't subscribed to LKML, and it means patches like this may get missed.
Quoted 26 lines · On Fri, Jul 17, 2020 at 04:33:38PM +0200, [email protected] wrote:
From: Gregory Herrero <[email protected]>
Currently, if a section has a relocation to '
_mcount' symbol, a new__mcount_locentry will be added whatever the relocation type is. This is problematic when a relocation to '_mcount' is in the middle of a section and is not a call for ftrace use.Such relocation could be generated with below code for example:
bool is_mcount(unsigned long addr) { return (target == (unsigned long) &_mcount); }With this snippet of code, ftrace will try to patch the mcount location generated by this code on module load and fail with:
Call trace: ftrace_bug+0xa0/0x28c ftrace_process_locs+0x2f4/0x430 ftrace_module_init+0x30/0x38 load_module+0x14f0/0x1e78 __do_sys_finit_module+0x100/0x11c __arm64_sys_finit_module+0x28/0x34 el0_svc_common+0x88/0x194 el0_svc_handler+0x38/0x8c el0_svc+0x8/0xc
Quoted 8 lines
---[ end trace d828d06b36ad9d59 ]---
ftrace failed to modify
[<ffffa2dbf3a3a41c>] 0xffffa2dbf3a3a41c
actual: 66:a9:3c:90
Initializing ftrace call sites
ftrace record flags: 2000000
(0)
expected tramp: ffffa2dc6cf66724Which code specifically is this triggering for? Is this something in an upstream kernel, or out-of-tree patches?
Can you say which toolchain you're using, too?
Quoted 2 lines
So Limit the relocation type to
R_AARCH64_CALL26as in perl version of recordmcount.
Given our patching code expects each callsite to be:
bl _mcount
... this looks sane to me, and I *think* that's sound for modules too.
Quoted 1 line
Fixes ed60453fa8f8 ("ARM: 6511/1: ftrace: add ARM support for C version of recordmcount")
That's a 32-bit arm commit. I suspect that was meant to be:
Quoted 22 lines
Signed-off-by Gregory Herrero <[email protected]>--- scripts/recordmcount.c | 6 ++++++ 1 file changed, 6 insertions(+)scripts/recordmcount.c +5
-0@@ -434,6 +434,11 @@ static int arm_is_fake_mcount(Elf32_Rel const *rp)return 1 ; } +static int arm64_is_fake_mcount (Elf64_Rel const *rp) +{ +return ELF64_R_TYPE (w (rp->r_info)) !=R_AARCH64_CALL26 ; +} +/* 64-bit EM_MIPS has weird ELF64_Rela.r_info. * http://techpubs.sgi.com/library/manuals/4000/007-4658-001/pdf/007-4658-001.pdf * We interpret Table 29 Relocation Operation (Elf64_Rel, Elf64_Rela) [p.40]
scripts/recordmcount.c static int do_file(char const *const fname) · line 556
Quoted 5 lines
scripts/recordmcount.c +1
-0@@ -547,6 +552,7 @@ static int do_file(char const *const fname) make_nop = make_nop_arm64; rel_type_nop =R_AARCH64_NONE ; ideal_nop = ideal_nop4_arm64; + is_fake_mcount64 = arm64_is_fake_mcount;break ;
As above, I think this is sound, but if you could answer my questions that'd be helpful.
Thanks,
Mark.
Quoted 5 lines
scripts/recordmcount.c +0
-0case EM_IA_64 : reltype =R_IA64_IMM64 ;break ;case EM_MIPS :/* reltype: e_class */ break ;Signature · 1 line
2.27.0
Hi Mark,
Quoted 7 lines · Mark Rutland
Hi Gregory,
As a general thing, for patches affecting arm64 could you please Cc the linx-arm-kernel mailing list ([email protected]). Some folk working on arm/arm64 aren't subscribed to LKML, and it means patches like this may get missed.
Got it, I will do that next time.
Quoted 36 lines · On Fri, Jul 17, 2020 at 04:33:38PM +0200, [email protected] wrote:
Quoted 26 lines
From: Gregory Herrero <[email protected]>
Currently, if a section has a relocation to '
_mcount' symbol, a new__mcount_locentry will be added whatever the relocation type is. This is problematic when a relocation to '_mcount' is in the middle of a section and is not a call for ftrace use.Such relocation could be generated with below code for example:
bool is_mcount(unsigned long addr) { return (target == (unsigned long) &_mcount); }With this snippet of code, ftrace will try to patch the mcount location generated by this code on module load and fail with:
Call trace: ftrace_bug+0xa0/0x28c ftrace_process_locs+0x2f4/0x430 ftrace_module_init+0x30/0x38 load_module+0x14f0/0x1e78 __do_sys_finit_module+0x100/0x11c __arm64_sys_finit_module+0x28/0x34 el0_svc_common+0x88/0x194 el0_svc_handler+0x38/0x8c el0_svc+0x8/0xcQuoted 8 lines
---[ end trace d828d06b36ad9d59 ]--- ftrace failed to modify [<ffffa2dbf3a3a41c>] 0xffffa2dbf3a3a41c actual: 66:a9:3c:90 Initializing ftrace call sites ftrace record flags: 2000000 (0) expected tramp: ffffa2dc6cf66724
Quoted 3 lines
Which code specifically is this triggering for? Is this something in an upstream kernel, or out-of-tree patches?
We faced this issue while porting Ksplice on ARM64 architecture. So that's an out-of-tree module. And we got this issue because we have multiple references to '_mcount' like the one described in the commit description of this patch.
Quoted 2 lines
Can you say which toolchain you're using, too?
We are using native gcc version: gcc (GCC) 7.3.0 20180125 (Red Hat 7.3.0-5) And native binutils 2.31.1.
Quoted 9 lines
Quoted 2 lines
So Limit the relocation type to
R_AARCH64_CALL26as in perl version of recordmcount.Given our patching code expects each callsite to be:
bl
_mcount... this looks sane to me, and I *think* that's sound for modules too.
Ok great.
Quoted 6 lines
Quoted 1 line
Fixes ed60453fa8f8 ("ARM: 6511/1: ftrace: add ARM support for C version of recordmcount")That's a 32-bit arm commit. I suspect that was meant to be:
Fixes af64d2aa872a1747 ("ftrace: Add arm64 support to recordmcount")
Right.
Quoted 22 lines
Quoted 22 lines
Signed-off-by Gregory Herrero <[email protected]>--- scripts/recordmcount.c | 6 ++++++ 1 file changed, 6 insertions(+)scripts/recordmcount.c +5
-0@@ -434,6 +434,11 @@ static int arm_is_fake_mcount(Elf32_Rel const *rp)return 1 ; } +static int arm64_is_fake_mcount (Elf64_Rel const *rp) +{ +return ELF64_R_TYPE (w (rp->r_info)) !=R_AARCH64_CALL26 ; +} +/* 64-bit EM_MIPS has weird ELF64_Rela.r_info. * http://techpubs.sgi.com/library/manuals/4000/007-4658-001/pdf/007-4658-001.pdf * We interpret Table 29 Relocation Operation (Elf64_Rel, Elf64_Rela) [p.40] @@ -547,6 +552,7 @@ static int do_file(char const *const fname)
Quoted 9 lines
scripts/recordmcount.c static int do_file(char const *const fname) · line 556
Quoted 5 lines
scripts/recordmcount.c +1
-0make_nop = make_nop_arm64; rel_type_nop =R_AARCH64_NONE ; ideal_nop = ideal_nop4_arm64; + is_fake_mcount64 = arm64_is_fake_mcount;break ;As above, I think this is sound, but if you could answer my questions that'd be helpful.
Thanks for the review,
Greg
Catalin Marinas
AppliedQuoted 5 lines · On Fri, 17 Jul 2020 16:33:38 +0200, [email protected] wrote:
Currently, if a section has a relocation to '
_mcount' symbol, a new__mcount_locentry will be added whatever the relocation type is. This is problematic when a relocation to '_mcount' is in the middle of a section and is not a call for ftrace use.
Quoted 7 lines
Such relocation could be generated with below code for example:
bool is_mcount(unsigned long addr) { return (target == (unsigned long) &_mcount); }[...]
Applied to arm64 (for-next/misc), thanks!
[1/1] recordmcount: only record relocation of type R_AARCH64_CALL26 on arm64.
https://git.kernel.org/arm64/c/ea0eada45632
Signature · 1 line
Catalin