mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Bradley Morgan <brads@mainlining.org>
To: Avi Weiss <thnkslprpt@gmail.com>
Cc: akpm@linux-foundation.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] profiling: fix sampling step on 64-bit big-endian systems
Date: Tue, 20 Oct 2026 17:50:24 +0100	[thread overview]
Message-ID: <FBD0DC2E-B6C0-400A-A2C2-BA8BA127E43E@mainlining.org> (raw)
In-Reply-To: <CAKOB7-YhfVyoo95LtfOSkJTVxgjOA0bxPBndca5L+9M9MXTSHw@mail.gmail.com>

On 20 October 2026 17:47:22 BST, Avi Weiss <thnkslprpt@gmail.com> wrote:
>I'm happy to try it anyway - just so I know how for future patches.
>I'll see how many I can run through before my laptop gives up ;-)

sometimes the crux is for these kinds of patches something in some cryptic
arch gets messed up in vmlinux stage, odd right?

This *makes sense* for me, off the top of my head and thinking hard id say
this *shouldn't* do anything bad to a cryptic architecture, but I've been
shocked in the past.

>
>On Tue, 20 Oct 2026 at 18:07, Bradley Morgan <brads@mainlining.org> wrote:
>>
>> On 20 October 2026 11:12:24 BST, Avi Weiss <thnkslprpt@gmail.com> wrote:
>> >read_profile() stores the sampling step in an unsigned long
>> >but copies only four bytes to userspace. On 64-bit
>> >big-endian systems (not common obviously), this copies
>> >the upper 32 bits and discards teh rest, causing
>> >/proc/profile to report zero for normal shift values.
>> >
>> >Cast to unsigned int so we get the correct 4 bytes, while
>> >keeping the shift calculation in unsigned long.
>> >
>> >A small C reproducer under qemu-s390x reproduced this and
>> >proved the fix works for prof_shift=2.
>>
>> If you wanna be 100% sure that this is regression free, you could test
>> building on all arches. Sometimes linking fails in cases.
>>
>> >
>> >Fixes: 2d186afd04d6 ("profiling: fix shift-out-of-bounds bugs")
>> >Signed-off-by: Avi Weiss <thnkslprpt@gmail.com>
>> >---
>> >
>> > kernel/profile.c | 2 +-
>> > 1 file changed, 1 insertion(+), 1 deletion(-)
>> >
>> >diff --git a/kernel/profile.c b/kernel/profile.c
>> >index 1fcf1adcf4eb0..e7defa90a34c9 100644
>> >--- a/kernel/profile.c
>> >+++ b/kernel/profile.c
>> >@@ -156,7 +156,7 @@ read_profile(struct file *file, char __user *buf,
>size_t count, loff_t *ppos)
>> >       unsigned long p = *ppos;
>> >       ssize_t read;
>> >       char *pnt;
>> >-      unsigned long sample_step = 1UL << prof_shift;
>> >+      unsigned int sample_step = (unsigned int)(1UL << prof_shift);
>>
>> But this would compile anyway.
>>
>> Reviewed-by: Bradley Morgan <brads@mainlining.org>
>>
>>
>> >
>> >       if (p >= (prof_len+1)*sizeof(unsigned int))
>> >               return 0;
>> >
>>
>> --- Thanks!
>> "I'm not a very positive person" - Linus torvalds
>

--- Thanks!
"I'm not a very positive person" - Linus torvalds

  reply	other threads:[~2026-10-20 16:50 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-20 10:12 Avi Weiss
2026-10-20 15:07 ` Bradley Morgan
2026-10-20 16:47   ` Avi Weiss
2026-10-20 16:50     ` Bradley Morgan [this message]
2026-10-21  0:46       ` Andrew Morton
2026-10-21  3:13         ` Avi Weiss

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=FBD0DC2E-B6C0-400A-A2C2-BA8BA127E43E@mainlining.org \
    --to=brads@mainlining.org \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=thnkslprpt@gmail.com \
    /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

all inboxes | Powered by JetHome®