linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Jason Baron <jbaron@akamai.com>
To: Josh Poimboeuf <jpoimboe@kernel.org>
Cc: Steven Rostedt <rostedt@goodmis.org>,
	Sam Sun <samsun1006219@gmail.com>,
	linux-kernel@vger.kernel.org, syzkaller@googlegroups.com,
	xrivendell7@gmail.com, ardb@kernel.org, peterz@infradead.org,
	linux-mm@kvack.org, akpm@linux-foundation.org,
	Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: [Bug] WARNING in static_key_disable_cpuslocked
Date: Wed, 6 Mar 2024 17:40:11 -0500	[thread overview]
Message-ID: <8f586bd2-c436-4334-92af-762a284e1101@akamai.com> (raw)
In-Reply-To: <20240306221650.sw3lha7kca2quv63@treble>



On 3/6/24 5:16 PM, Josh Poimboeuf wrote:
> On Wed, Mar 06, 2024 at 03:12:07PM -0500, Jason Baron wrote:
>>
>>
>> On 3/6/24 2:31 PM, Josh Poimboeuf wrote:
>>> On Wed, Mar 06, 2024 at 10:54:20AM -0500, Steven Rostedt wrote:
>>>> Now I guess the question is, why is something trying to disable something
>>>> that is not enabled? Is the above scenario OK? Or should the users of
>>>> static_key also prevent this?
>>>
>>> Apparently that's an allowed scenario, as the jump label code seems to
>>> be actively trying to support it.  Basically the last one "wins".
>>>
>>> See for example:
>>>
>>>     1dbb6704de91 ("jump_label: Fix concurrent static_key_enable/disable()")
>>>
>>> Also the purpose of the first atomic_read() is to do a quick test before
>>> grabbing the jump lock.  So instead of grabbing the jump lock earlier,
>>> it should actually do the first test atomically:
>>
>> Makes sense but the enable path can also set key->enabled to -1.
> 
> Ah, this code is really subtle :-/
> 
>> So I think a concurrent disable could then see the -1 in tmp and still
>> trigger the WARN.
> 
> I think this shouldn't be possible, for the same reason that
> static_key_slow_try_dec() warns on -1:  key->enabled can only be -1
> during the first enable.  And disable should never be called before
> then.

hmm, right but I think in this case the reproducer is writing to a sysfs 
file to enable/disable randomly so i'm not sure if there is anything 
that would enforce that ordering. I guess you could try the reproducer, 
I haven't really looked at it in any detail.

The code in question here is in mm/vmscan.c which actually already takes 
the local 'state_mutex' for some cases. So that could be extended I 
think easily to avoid this warning.

> 
>> So I think we could change the WARN to be:
>> WARN_ON_ONCE(tmp != 0 && tmp != -1). And also add a similar check
>> for enable if we have enable vs enable racing?
> 
> My patch subtly changed the "key->enabled > 0" to "key->enabled != 0".
> If I change that back then it should be fine.
> 
>> Although it seems like the set key->enabled to -1 while used in the inc/dec
>> API isn't really doing anything in the enable/disable part here?
>> But then the key->enabled I think has to move in front of the
>> jump_label_update() to make that part work right...
> 
> Yeah, this code needs better comments.  Let me turn it into a proper
> patch.
> 


  reply	other threads:[~2024-03-06 22:40 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-05  7:54 Sam Sun
2024-03-06 15:54 ` Steven Rostedt
2024-03-06 19:31   ` Josh Poimboeuf
2024-03-06 20:12     ` Jason Baron
2024-03-06 22:16       ` Josh Poimboeuf
2024-03-06 22:40         ` Jason Baron [this message]
2024-03-06 23:42           ` Josh Poimboeuf
2024-03-07  1:30             ` Josh Poimboeuf
2024-03-07  2:34               ` Steven Rostedt

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=8f586bd2-c436-4334-92af-762a284e1101@akamai.com \
    --to=jbaron@akamai.com \
    --cc=akpm@linux-foundation.org \
    --cc=ardb@kernel.org \
    --cc=jpoimboe@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=pbonzini@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=samsun1006219@gmail.com \
    --cc=syzkaller@googlegroups.com \
    --cc=xrivendell7@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