public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] scripts/sorttable: Fix endianness handling in build-time mcount sort
@ 2025-04-02  1:15 Vasily Gorbik
  2025-04-02 23:22 ` Ihor Solodrai
  0 siblings, 1 reply; 4+ messages in thread
From: Vasily Gorbik @ 2025-04-02  1:15 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: Masami Hiramatsu, Catalin Marinas, Nathan Chancellor,
	Ilya Leoshkevich, Ihor Solodrai, Heiko Carstens,
	Alexander Gordeev, linux-kernel

Kernel cross-compilation with BUILDTIME_MCOUNT_SORT produces zeroed
mcount values if the build-host endianness does not match the ELF
file endianness.

The mcount values array is converted from ELF file
endianness to build-host endianness during initialization in
fill_relocs()/fill_addrs(). Avoid extra conversion of these values during
weak-function zeroing; otherwise, they do not match nm-parsed addresses
and all mcount values are zeroed out.

Fixes: ef378c3b8233 ("scripts/sorttable: Zero out weak functions in mcount_loc table")
Reported-by: Ilya Leoshkevich <iii@linux.ibm.com>
Reported-by: Ihor Solodrai <ihor.solodrai@linux.dev>
Closes: https://lore.kernel.org/all/your-ad-here.call-01743522822-ext-4975@work.hours/
Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
---
 scripts/sorttable.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/sorttable.c b/scripts/sorttable.c
index 7b4b3714b1af..deed676bfe38 100644
--- a/scripts/sorttable.c
+++ b/scripts/sorttable.c
@@ -857,7 +857,7 @@ static void *sort_mcount_loc(void *arg)
 		for (void *ptr = vals; ptr < vals + size; ptr += long_size) {
 			uint64_t key;
 
-			key = long_size == 4 ? r((uint32_t *)ptr) : r8((uint64_t *)ptr);
+			key = long_size == 4 ? *(uint32_t *)ptr : *(uint64_t *)ptr;
 			if (!find_func(key)) {
 				if (long_size == 4)
 					*(uint32_t *)ptr = 0;
-- 
2.48.1

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

* Re: [PATCH] scripts/sorttable: Fix endianness handling in build-time mcount sort
  2025-04-02  1:15 [PATCH] scripts/sorttable: Fix endianness handling in build-time mcount sort Vasily Gorbik
@ 2025-04-02 23:22 ` Ihor Solodrai
  2025-04-02 23:28   ` Steven Rostedt
  0 siblings, 1 reply; 4+ messages in thread
From: Ihor Solodrai @ 2025-04-02 23:22 UTC (permalink / raw)
  To: Vasily Gorbik, Steven Rostedt
  Cc: Masami Hiramatsu, Catalin Marinas, Nathan Chancellor,
	Ilya Leoshkevich, Heiko Carstens, Alexander Gordeev, linux-kernel,
	bpf

On 4/1/25 6:15 PM, Vasily Gorbik wrote:
> Kernel cross-compilation with BUILDTIME_MCOUNT_SORT produces zeroed
> mcount values if the build-host endianness does not match the ELF
> file endianness.
>
> The mcount values array is converted from ELF file
> endianness to build-host endianness during initialization in
> fill_relocs()/fill_addrs(). Avoid extra conversion of these values during
> weak-function zeroing; otherwise, they do not match nm-parsed addresses
> and all mcount values are zeroed out.
>
> Fixes: ef378c3b8233 ("scripts/sorttable: Zero out weak functions in mcount_loc table")
> Reported-by: Ilya Leoshkevich <iii@linux.ibm.com>
> Reported-by: Ihor Solodrai <ihor.solodrai@linux.dev>
> Closes: https://lore.kernel.org/all/your-ad-here.call-01743522822-ext-4975@work.hours/
> Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
> ---
>  scripts/sorttable.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/scripts/sorttable.c b/scripts/sorttable.c
> index 7b4b3714b1af..deed676bfe38 100644
> --- a/scripts/sorttable.c
> +++ b/scripts/sorttable.c
> @@ -857,7 +857,7 @@ static void *sort_mcount_loc(void *arg)
>  		for (void *ptr = vals; ptr < vals + size; ptr += long_size) {
>  			uint64_t key;
>  
> -			key = long_size == 4 ? r((uint32_t *)ptr) : r8((uint64_t *)ptr);
> +			key = long_size == 4 ? *(uint32_t *)ptr : *(uint64_t *)ptr;
>  			if (!find_func(key)) {
>  				if (long_size == 4)
>  					*(uint32_t *)ptr = 0;

Hi Vasily,

I can confirm that this patch fixes BPF selftests on s390x:
https://github.com/kernel-patches/vmtest/actions/runs/14231181710

Tested-by: Ihor Solodrai <ihor.solodrai@linux.dev>

Thank you!

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

* Re: [PATCH] scripts/sorttable: Fix endianness handling in build-time mcount sort
  2025-04-02 23:22 ` Ihor Solodrai
@ 2025-04-02 23:28   ` Steven Rostedt
  2025-04-02 23:32     ` Ihor Solodrai
  0 siblings, 1 reply; 4+ messages in thread
From: Steven Rostedt @ 2025-04-02 23:28 UTC (permalink / raw)
  To: Ihor Solodrai
  Cc: Vasily Gorbik, Masami Hiramatsu, Catalin Marinas,
	Nathan Chancellor, Ilya Leoshkevich, Heiko Carstens,
	Alexander Gordeev, linux-kernel, bpf

On Wed, 02 Apr 2025 23:22:40 +0000
"Ihor Solodrai" <ihor.solodrai@linux.dev> wrote:

> Hi Vasily,
> 
> I can confirm that this patch fixes BPF selftests on s390x:
> https://github.com/kernel-patches/vmtest/actions/runs/14231181710
> 
> Tested-by: Ihor Solodrai <ihor.solodrai@linux.dev>

Thanks, but I already submitted a pull request that includes this fix, as
it looked pretty obvious (I did run it through all my normal tests, but
just didn't test the big/little endian case).

  https://lore.kernel.org/all/20250402174449.08caae28@gandalf.local.home/

-- Steve

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

* Re: [PATCH] scripts/sorttable: Fix endianness handling in build-time mcount sort
  2025-04-02 23:28   ` Steven Rostedt
@ 2025-04-02 23:32     ` Ihor Solodrai
  0 siblings, 0 replies; 4+ messages in thread
From: Ihor Solodrai @ 2025-04-02 23:32 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: Vasily Gorbik, Masami Hiramatsu, Catalin Marinas,
	Nathan  Chancellor, Ilya Leoshkevich, Heiko Carstens,
	Alexander Gordeev, linux-kernel, bpf

On 4/2/25 4:28 PM, Steven Rostedt wrote:
> On Wed, 02 Apr 2025 23:22:40 +0000
> "Ihor Solodrai" <ihor.solodrai@linux.dev> wrote:
>
>> Hi Vasily,
>>
>> I can confirm that this patch fixes BPF selftests on s390x:
>> https://github.com/kernel-patches/vmtest/actions/runs/14231181710
>>
>> Tested-by: Ihor Solodrai <ihor.solodrai@linux.dev>
>
> Thanks, but I already submitted a pull request that includes this fix, as
> it looked pretty obvious (I did run it through all my normal tests, but
> just didn't test the big/little endian case).
>
>   https://lore.kernel.org/all/20250402174449.08caae28@gandalf.local.home/

Sure, that's fine. I had to test it anyway, so that a revert
fa1518875286 patch could be removed from CI. Just sharing a data
point.

Thank you.

>
> -- Steve

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

end of thread, other threads:[~2025-04-02 23:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-02  1:15 [PATCH] scripts/sorttable: Fix endianness handling in build-time mcount sort Vasily Gorbik
2025-04-02 23:22 ` Ihor Solodrai
2025-04-02 23:28   ` Steven Rostedt
2025-04-02 23:32     ` Ihor Solodrai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox