mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Mashiro Chen <mashiro.chen@mailbox.org>
To: Johannes Weiner <hannes@cmpxchg.org>
Cc: surenb@google.com, peterz@infradead.org, mingo@redhat.com,
	juri.lelli@redhat.com, vincent.guittot@linaro.org,
	dietmar.eggemann@arm.com, rostedt@goodmis.org,
	bsegall@google.com, mgorman@suse.de, vschneid@redhat.com,
	akpm@linux-foundation.org, linux-kernel@vger.kernel.org,
	syzbot+4b1bd55fba6260160779@syzkaller.appspotmail.com
Subject: Re: [PATCH] sched/psi: initialize *flags in psi_memstall_enter when PSI is disabled
Date: Thu, 9 Apr 2026 00:58:03 +0800	[thread overview]
Message-ID: <199e0730-d35e-4617-b5c3-608934ecaa3d@mailbox.org> (raw)
In-Reply-To: <adaE-bHBJrh5FITI@cmpxchg.org>

Hi Johannes,

You're right on both counts. The 'opaque channel' framing makes it
clear there's no meaningful API contract being violated here -- the
caller is not supposed to interpret *flags at all.

And yes, your second point is exactly the real issue: once a stack
frame returns, its local variables should be considered dead. KMSAN
tracking that shadow across page reuse into an unrelated frame is the
actual bug.

I'll drop this patch. The correct fix is in KMSAN -- it should treat
stack slots as out-of-scope once their owning frame returns, rather
than letting stale shadow metadata escape into subsequent users of
the same physical address.

Thanks for the clear explanation.

Best,
Mashiro Chen

On 4/9/26 00:40, Johannes Weiner wrote:
> On Thu, Apr 09, 2026 at 12:14:50AM +0800, Mashiro Chen wrote:
>> Hi Johannes,
>>
>> Good question. You're right that KMSAN's stack tracking persisting
>> across page reuse boundaries is arguably a tool limitation. That said,
>> I think fixing it on the PSI side is still reasonable:
>>
>> psi_memstall_enter() takes a pointer parameter with an implicit contract:
>> if the caller passes &flags, they expect *flags to be initialized upon
>> return. The current early-return silently violates that contract by
>> leaving *flags uninitialized, even though the value is never actually used
>> functionally.
> The caller has no expectations towards the contents of *flags and no
> business reading or manipulating them. It's an opaque channel that
> lets _enter() communicate with _leave().
>
>> The fix is essentially free (we're already in the early-return path) and
>> makes the contract explicit. You're right that the original patch lacked
>> a comment explaining this, I should have added:
>>
>>       /* Initialize to 0 even in psi_disabled case to honor the
>>        * implicit API contract that *flags is initialized on return.
>>        * psi_memstall_leave() also returns early when psi_disabled
>>        * and does not read *flags, so this is zero-cost. */
>>       *flags = 0;
>>       return;
>>
>> That said, if you prefer this stays in KMSAN (e.g., treating stack
>> variables as out-of-scope once their frame returns), I'm happy to drop
>> the patch and redirect the effort there instead.
> It sounds to me like this would be a good thing to fix regardless of
> what psi is doing here. Even if psi initialized it to some value that
> is meaningful to psi - that value is totally random, and for all
> intents and purposes "uninitialized", from the view of a subsequent
> user of that stack slot?

      reply	other threads:[~2026-04-08 16:58 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-05  5:50 Mashiro Chen
2026-04-08 15:10 ` Johannes Weiner
2026-04-08 16:14   ` Mashiro Chen
2026-04-08 16:40     ` Johannes Weiner
2026-04-08 16:58       ` Mashiro Chen [this message]

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=199e0730-d35e-4617-b5c3-608934ecaa3d@mailbox.org \
    --to=mashiro.chen@mailbox.org \
    --cc=akpm@linux-foundation.org \
    --cc=bsegall@google.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=hannes@cmpxchg.org \
    --cc=juri.lelli@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=surenb@google.com \
    --cc=syzbot+4b1bd55fba6260160779@syzkaller.appspotmail.com \
    --cc=vincent.guittot@linaro.org \
    --cc=vschneid@redhat.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®