recordmcount: Fix the wrong use of w* in arm64_is_fake_mcount()
PATCH 1/1 recordmcount: Fix the wrong use of w* in arm64_is_fake_mcount()
When cross-compiling the kernel, the endian of the target machine and the local machine may not match, at this time the recordmcount tool needs byte reversal when processing elf's variables to get the correct value. w* callback function is used to solve this problem, w is used for 4-byte variable processing, while w8 is used for 8-byte.
arm64_is_fake_mcount() is used to filter '_mcount' relocations that are not used by ftrace. In arm64_is_fake_mcount(), rp->info is 8 bytes in size, but w is used. This causes arm64_is_fake_mcount() to get the wrong type of relocation when we cross-compile the arm64_be kernel image on an x86_le machine, and all valid '_mcount' is filtered out. The recordmcount tool does not collect any mcount function call locations. At kernel startup, the following ftrace log is seen:
ftrace: No functions to be traced?
and thus ftrace cannot be used.
Using w8 to get the value of rp->r_info will fix the problem.
R_AARCH64_CALL26 on arm64")
--- scripts/recordmcount.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/recordmcount.c +1 -1
@@ -438,7 +438,7 @@ static int arm_is_fake_mcount(Elf32_Rel const *rp)static int arm64_is_fake_mcount (Elf64_Rel const *rp) { -return ELF64_R_TYPE (w (rp->r_info)) !=R_AARCH64_CALL26 ; +return ELF64_R_TYPE (w8 (rp->r_info)) !=R_AARCH64_CALL26 ; }/* 64-bit EM_MIPS has weird ELF64_Rela.r_info.
Signature · 1 line
2.17.1
This requires an acked-by from one of the ARM64 maintainers.
-- Steve
Quoted 40 lines · On Thu, 25 Feb 2021 22:07:47 +0800 Li Huafei <[email protected]> wrote:
When cross-compiling the kernel, the endian of the target machine and the local machine may not match, at this time the recordmcount tool needs byte reversal when processing elf's variables to get the correct value. w* callback function is used to solve this problem, w is used for 4-byte variable processing, while w8 is used for 8-byte.
arm64_is_fake_mcount()is used to filter '_mcount' relocations that are not used by ftrace. Inarm64_is_fake_mcount(),rp->infois 8 bytes in size, but w is used. This causesarm64_is_fake_mcount()to get the wrong type of relocation when we cross-compile thearm64_bekernel image on anx86_lemachine, and all valid '_mcount' is filtered out. The recordmcount tool does not collect any mcount function call locations. At kernel startup, the following ftrace log is seen:ftrace: No functions to be traced?
and thus ftrace cannot be used.
Using w8 to get the value of
rp->r_infowill fix the problem.Fixes ea0eada45632 ("recordmcount: only record relocation of type
R_AARCH64_CALL26on arm64")Signed-off-by Li Huafei <[email protected]>--- scripts/recordmcount.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)scripts/recordmcount.c +1
-1@@ -438,7 +438,7 @@ static int arm_is_fake_mcount(Elf32_Rel const *rp)static int arm64_is_fake_mcount (Elf64_Rel const *rp) { -return ELF64_R_TYPE (w (rp->r_info)) !=R_AARCH64_CALL26 ; +return ELF64_R_TYPE (w8 (rp->r_info)) !=R_AARCH64_CALL26 ; }/* 64-bit EM_MIPS has weird ELF64_Rela.r_info.
Will Deacon
Acked-byQuoted 41 lines · Steven Rostedt
This requires an acked-by from one of the ARM64 maintainers.
-- Steve
Quoted 33 lines · On Thu, 25 Feb 2021 22:07:47 +0800 Li Huafei <[email protected]> wrote:
When cross-compiling the kernel, the endian of the target machine and the local machine may not match, at this time the recordmcount tool needs byte reversal when processing elf's variables to get the correct value. w* callback function is used to solve this problem, w is used for 4-byte variable processing, while w8 is used for 8-byte.
arm64_is_fake_mcount()is used to filter '_mcount' relocations that are not used by ftrace. Inarm64_is_fake_mcount(),rp->infois 8 bytes in size, but w is used. This causesarm64_is_fake_mcount()to get the wrong type of relocation when we cross-compile thearm64_bekernel image on anx86_lemachine, and all valid '_mcount' is filtered out. The recordmcount tool does not collect any mcount function call locations. At kernel startup, the following ftrace log is seen:ftrace: No functions to be traced?
and thus ftrace cannot be used.
Using w8 to get the value of
rp->r_infowill fix the problem.Fixes ea0eada45632 ("recordmcount: only record relocation of type
R_AARCH64_CALL26on arm64")Signed-off-by Li Huafei <[email protected]>--- scripts/recordmcount.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)scripts/recordmcount.c +0
-0@@ -438,7 +438,7 @@ static int arm_is_fake_mcount(Elf32_Rel const *rp)
Quoted 4 lines
scripts/recordmcount.c static int arm_is_fake_mcount(Elf32_Rel const *rp) · line 441
Quoted 4 lines
scripts/recordmcount.c +1
-1static int arm64_is_fake_mcount (Elf64_Rel const *rp) { -return ELF64_R_TYPE (w (rp->r_info)) !=R_AARCH64_CALL26 ; +return ELF64_R_TYPE (w8 (rp->r_info)) !=R_AARCH64_CALL26 ;
But you know you could avoid these sorts of problems by moving to little endian along with everybody else? ;)
Will
Quoted 1 line · On Thu, 25 Feb 2021 16:01:17 +0000 Will Deacon <[email protected]> wrote:
Acked-by Will Deacon <[email protected]>
Thanks!
Quoted 3 lines
But you know you could avoid these sorts of problems by moving to little endian along with everybody else? ;)
But then how do we find these bug?
-- Steve
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Quoted 49 lines · On Thu, 25 Feb 2021 16:01:17 +0000 Will Deacon <[email protected]> wrote:
Quoted 41 lines · Steven Rostedt
This requires an acked-by from one of the ARM64 maintainers.
-- Steve
Quoted 33 lines · On Thu, 25 Feb 2021 22:07:47 +0800 Li Huafei <[email protected]> wrote:
When cross-compiling the kernel, the endian of the target machine and the local machine may not match, at this time the recordmcount tool needs byte reversal when processing elf's variables to get the correct value. w* callback function is used to solve this problem, w is used for 4-byte variable processing, while w8 is used for 8-byte.
arm64_is_fake_mcount()is used to filter '_mcount' relocations that are not used by ftrace. Inarm64_is_fake_mcount(),rp->infois 8 bytes in size, but w is used. This causesarm64_is_fake_mcount()to get the wrong type of relocation when we cross-compile thearm64_bekernel image on anx86_lemachine, and all valid '_mcount' is filtered out. The recordmcount tool does not collect any mcount function call locations. At kernel startup, the following ftrace log is seen:ftrace: No functions to be traced?
and thus ftrace cannot be used.
Using w8 to get the value of
rp->r_infowill fix the problem.Fixes ea0eada45632 ("recordmcount: only record relocation of type
R_AARCH64_CALL26on arm64")Signed-off-by Li Huafei <[email protected]>--- scripts/recordmcount.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)scripts/recordmcount.c +0
-0@@ -438,7 +438,7 @@ static int arm_is_fake_mcount(Elf32_Rel const *rp)Quoted 4 lines
scripts/recordmcount.c static int arm_is_fake_mcount(Elf32_Rel const *rp) · line 441
Quoted 4 lines
scripts/recordmcount.c +1
-1static int arm64_is_fake_mcount (Elf64_Rel const *rp) { -return ELF64_R_TYPE (w (rp->r_info)) !=R_AARCH64_CALL26 ; +return ELF64_R_TYPE (w8 (rp->r_info)) !=R_AARCH64_CALL26 ;Acked-by Will Deacon <[email protected]>
Quoted 3 lines
But you know you could avoid these sorts of problems by moving to little endian along with everybody else? ;)
I just realized that I received this patch twice, and thought it was the same patch! Chen was three days ahead of you, so he get's the credit ;-)
https://lore.kernel.org/r/[email protected]
-- Steve
Steven Rostedt
Acked-by Will DeaconQuoted 4 lines · On Tue, 2 Mar 2021 17:30:58 -0500 Steven Rostedt <[email protected]> wrote:
I just realized that I received this patch twice, and thought it was the same patch! Chen was three days ahead of you, so he get's the credit ;-)
I'm applying this patch (same one here but came earlier).
Will, you still OK with your acked-by on it?
-- Steve
From 999340d51174ce4141dd723105d4cef872b13ee9 Mon Sep 17 00:00:00 2001
From: Chen Jun <[email protected]>
Date: Mon, 22 Feb 2021 13:58:40 +0000
Subject: [PATCH] ftrace: Have recordmcount use w8 to read relp->r_info in
arm64_is_fake_mcount
On little endian system, Use aarch64_be(gcc v7.3) downloaded from linaro.org to build image with CONFIG_CPU_BIG_ENDIAN = y, CONFIG_FTRACE = y, CONFIG_DYNAMIC_FTRACE = y.
gcc will create symbols of _mcount but recordmcount can not create mcount_loc for *.o.
aarch64_be-linux-gnu-objdump -r fs/namei.o | grep mcount 00000000000000d0 R_AARCH64_CALL26 _mcount
...
0000000000007190 R_AARCH64_CALL26 _mcount
The reason is than funciton arm64_is_fake_mcount can not work correctly. A symbol of _mcount in *.o compiled with big endian compiler likes:
00 00 00 2d 00 00 01 1bw(rp->r_info) will return 0x2d instead of 0x011b. Because w() takes uint32_t as parameter, which truncates rp->r_info.
Use w8() instead w() to read relp->r_info
--- scripts/recordmcount.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/recordmcount.c +1 -1
@@ -438,7 +438,7 @@ static int arm_is_fake_mcount(Elf32_Rel const *rp)static int arm64_is_fake_mcount (Elf64_Rel const *rp) { -return ELF64_R_TYPE (w (rp->r_info)) !=R_AARCH64_CALL26 ; +return ELF64_R_TYPE (w8 (rp->r_info)) !=R_AARCH64_CALL26 ; }/* 64-bit EM_MIPS has weird ELF64_Rela.r_info.
Signature · 1 line
2.25.4
Quoted 11 lines · Steven Rostedt
Quoted 4 lines · On Tue, 2 Mar 2021 17:30:58 -0500 Steven Rostedt <[email protected]> wrote:
I just realized that I received this patch twice, and thought it was the same patch! Chen was three days ahead of you, so he get's the credit ;-)
I'm applying this patch (same one here but came earlier).
Will, you still OK with your acked-by on it?
Absolutely!
Will
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Quoted 56 lines · Steven Rostedt
Quoted 49 lines · On Thu, 25 Feb 2021 16:01:17 +0000 Will Deacon <[email protected]> wrote:
Quoted 41 lines · Steven Rostedt
This requires an acked-by from one of the ARM64 maintainers.
-- Steve
Quoted 33 lines · On Thu, 25 Feb 2021 22:07:47 +0800 Li Huafei <[email protected]> wrote:
When cross-compiling the kernel, the endian of the target machine and the local machine may not match, at this time the recordmcount tool needs byte reversal when processing elf's variables to get the correct value. w* callback function is used to solve this problem, w is used for 4-byte variable processing, while w8 is used for 8-byte.
arm64_is_fake_mcount()is used to filter '_mcount' relocations that are not used by ftrace. Inarm64_is_fake_mcount(),rp->infois 8 bytes in size, but w is used. This causesarm64_is_fake_mcount()to get the wrong type of relocation when we cross-compile thearm64_bekernel image on anx86_lemachine, and all valid '_mcount' is filtered out. The recordmcount tool does not collect any mcount function call locations. At kernel startup, the following ftrace log is seen:ftrace: No functions to be traced?
and thus ftrace cannot be used.
Using w8 to get the value of
rp->r_infowill fix the problem.Fixes ea0eada45632 ("recordmcount: only record relocation of type
R_AARCH64_CALL26on arm64")Signed-off-by Li Huafei <[email protected]>--- scripts/recordmcount.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)scripts/recordmcount.c +0
-0@@ -438,7 +438,7 @@ static int arm_is_fake_mcount(Elf32_Rel const *rp)Quoted 4 lines
scripts/recordmcount.c static int arm_is_fake_mcount(Elf32_Rel const *rp) · line 441
Quoted 4 lines
scripts/recordmcount.c +1
-1static int arm64_is_fake_mcount (Elf64_Rel const *rp) { -return ELF64_R_TYPE (w (rp->r_info)) !=R_AARCH64_CALL26 ; +return ELF64_R_TYPE (w8 (rp->r_info)) !=R_AARCH64_CALL26 ;Acked-by Will Deacon <[email protected]>Quoted 3 lines
But you know you could avoid these sorts of problems by moving to little endian along with everybody else? ;)
Quoted 8 lines
I just realized that I received this patch twice, and thought it was the same patch! Chen was three days ahead of you, so he get's the credit ;-)
https://lore.kernel.org/r/[email protected]
-- Steve
.
That's fine, thanks Steve and Will!
Huafei