From: Vlastimil Babka <vbabka@suse.cz>
To: Alexander Atanasov <alexander.atanasov@virtuozzo.com>,
Jonathan Corbet <corbet@lwn.net>,
Christoph Lameter <cl@linux.com>,
Pekka Enberg <penberg@kernel.org>,
David Rientjes <rientjes@google.com>,
Joonsoo Kim <iamjoonsoo.kim@lge.com>,
Andrew Morton <akpm@linux-foundation.org>,
Roman Gushchin <roman.gushchin@linux.dev>,
Hyeonggon Yoo <42.hyeyoo@gmail.com>
Cc: kernel@openvz.org, Kees Cook <keescook@chromium.org>,
Roman Gushchin <guro@fb.com>, Jann Horn <jannh@google.com>,
Vijayanand Jitta <vjitta@codeaurora.org>,
linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-mm@kvack.org
Subject: Re: [PATCH] mm: Make failslab writable again
Date: Tue, 20 Sep 2022 12:31:42 +0200 [thread overview]
Message-ID: <30b3c8d3-3e2e-8f07-a05e-3c91fccde024@suse.cz> (raw)
In-Reply-To: <7d79d13b-0579-452f-7a07-4e3eba205d23@virtuozzo.com>
On 9/20/22 12:21, Alexander Atanasov wrote:
> On 20.09.22 12:29, Vlastimil Babka wrote:
>> On 9/20/22 11:17, Alexander Atanasov wrote:
>>> Hello,
>>>
>>> On 20.09.22 11:42, Vlastimil Babka wrote:
>>>>> +static ssize_t failslab_store(struct kmem_cache *s, const char *buf,
>>>>> + size_t length)
>>>>> +{
>>>>> + if (s->refcount > 1)
>>>>> + return -EINVAL;
>>>>> +
>>>>> + s->flags &= ~SLAB_FAILSLAB;
>>>>> + if (buf[0] == '1')
>>>>> + s->flags |= SLAB_FAILSLAB;
>>>>
>>>> Could we at least use a temporary variable to set up the final value and
>>>> then do a WRITE_ONCE() to s->flags, so the compiler is not allowed to do
>>>> some funky stuff? Assuming this is really the only place where we modify
>>>> s->flags during runtime, so we can't miss other updates due to RMW.
>>>
>>> Since it is set or clear - instead of temporary variable and potentially two
>>> writes and RMW issues i would suggest this:
>>> + if (buf[0] == '1')
>>> + s->flags |= SLAB_FAILSLAB;
>>> + else
>>> + s->flags &= ~SLAB_FAILSLAB;
>>
>> This way also has RMW issues, and also the compiler is allowed to
>> temporarily modify s->flags any way it likes; with WRITE_ONCE() it can't.
>
> Okay, so the safest way is this?
>
> if (buf[0] == '1')
> WRITE_ONCE(s->flags, READ_ONCE(s->flags) | SLAB_FAILSLAB);
> else
> WRITE_ONCE(s->flags, READ_ONCE(s->flags) & ~SLAB_FAILSLAB);
Yeah, that would work. Given we are the only writer, we shouldn't even need
a READ_ONCE.
> It got me thinking how many places would break if the compiler
> starts to temporariliy modify the flags - i hope it never does.
That's likely true as well. But the macros have been introduced for this
purpose AFAIK.
prev parent reply other threads:[~2022-09-20 10:31 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-20 8:20 Alexander Atanasov
2022-09-20 8:42 ` Vlastimil Babka
2022-09-20 9:17 ` Alexander Atanasov
2022-09-20 9:29 ` Vlastimil Babka
2022-09-20 10:21 ` Alexander Atanasov
2022-09-20 10:31 ` Vlastimil Babka [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=30b3c8d3-3e2e-8f07-a05e-3c91fccde024@suse.cz \
--to=vbabka@suse.cz \
--cc=42.hyeyoo@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=alexander.atanasov@virtuozzo.com \
--cc=cl@linux.com \
--cc=corbet@lwn.net \
--cc=guro@fb.com \
--cc=iamjoonsoo.kim@lge.com \
--cc=jannh@google.com \
--cc=keescook@chromium.org \
--cc=kernel@openvz.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=penberg@kernel.org \
--cc=rientjes@google.com \
--cc=roman.gushchin@linux.dev \
--cc=vjitta@codeaurora.org \
/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