From: Joe Lawrence <joe.lawrence@redhat.com>
To: Mikulas Patocka <mpatocka@redhat.com>
Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
Alexander Viro <viro@zeniv.linux.org.uk>,
"Luis R. Rodriguez" <mcgrof@kernel.org>,
Kees Cook <keescook@chromium.org>,
Michael Kerrisk <mtk.manpages@gmail.com>,
Randy Dunlap <rdunlap@infradead.org>
Subject: Re: [PATCH RFC 2/3] pipe: protect pipe_max_size access with a mutex
Date: Tue, 19 Sep 2017 17:32:14 -0400 [thread overview]
Message-ID: <4121a697-d2fb-ec65-eea3-3c01592c8e08@redhat.com> (raw)
In-Reply-To: <alpine.LRH.2.02.1709190339020.15590@file01.intranet.prod.int.rdu2.redhat.com>
On 09/19/2017 03:53 AM, Mikulas Patocka wrote:
> On Fri, 15 Sep 2017, Joe Lawrence wrote:
> [ ... snip ... ]
>> Hi Mikulas,
>>
>> I'm not strong when it comes to memory barriers, but one of the
>> side-effects of using the mutex is that pipe_set_size() and
>> alloc_pipe_info() should have a consistent view of pipe_max_size.
>>
>> If I remove the mutex (and assume that I implement a custom
>> do_proc_dointvec "conv" callback), is it safe for these routines to
>> directly use pipe_max_size as they had done before?
>>
>> If not, is it safe to alias through a temporary stack variable (ie,
>> could the compiler re-read pipe_max_size multiple times in the function)?
>>
>> Would READ_ONCE() help in any way?
>
> Theoretically re-reading the variable is possible and you should use
> ACCESS_ONCE or READ_ONCE+WRITE_ONCE on that variable.
>
> In practice, ACCESS_ONCE/READ_ONCE/WRITE_ONCE is missing at a lot of
> kernel variables that could be modified asynchronously and no one is
> complaining about it and no one is making any systematic effort to fix it.
>
> That re-reading happens (I have some test code that makes the gcc
> optimizer re-read a variable), but it happens very rarely.
This would be interesting to look at if you are willing to share (can
send offlist).
> Another theoretical problem is that when reading or writing a variable
> without ACCESS_ONCE, the compiler could read and write the variable using
> multiple smaller memory accesses. But in practice, it happens only on some
> non-common architectures.
Smaller access than word size?
>> The mutex covered up some confusion on my part here.
>>
>> OTOH, since pipe_max_size is read-only for pipe_set_size() and
>> alloc_pipe_info() and only updated occasionally by pipe_proc_fn(), would
>> rw_semaphore or RCU be a fit here?
>
> RW semaphore causes cache-line ping-pong between CPUs, it slows down the
> kernel just like a normal spinlock or mutex.
Ah right.
> RCU would be useless here (i.e. you don't want to allocate memory and
> atomically assign it with rcu_assign_pointer).
And good point here.
Thanks for the explanations, they confirm and expand what I as already
thinking in this space.
--- Joe
next prev parent reply other threads:[~2017-09-19 21:32 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-05 14:44 [PATCH RFC 0/3] A few round_pipe_size() and pipe-max-size fixups Joe Lawrence
2017-09-05 14:44 ` [PATCH RFC 1/3] pipe: avoid round_pipe_size() nr_pages overflow on 32-bit Joe Lawrence
2017-09-05 14:44 ` [PATCH RFC 2/3] pipe: protect pipe_max_size access with a mutex Joe Lawrence
2017-09-14 23:09 ` Mikulas Patocka
2017-09-15 14:08 ` Joe Lawrence
2017-09-19 7:53 ` Mikulas Patocka
2017-09-19 21:32 ` Joe Lawrence [this message]
2017-09-21 10:05 ` Mikulas Patocka
2017-09-19 21:47 ` Joe Lawrence
2017-09-25 10:44 ` Mikulas Patocka
2017-09-05 14:44 ` [PATCH RFC 3/3] pipe: match pipe_max_size data type with procfs Joe Lawrence
2017-09-14 13:26 ` [PATCH RFC 0/3] A few round_pipe_size() and pipe-max-size fixups Michael Kerrisk (man-pages)
2017-09-14 16:57 ` Randy Dunlap
2017-09-14 19:19 ` Joe Lawrence
2017-09-14 20:22 ` Randy Dunlap
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=4121a697-d2fb-ec65-eea3-3c01592c8e08@redhat.com \
--to=joe.lawrence@redhat.com \
--cc=keescook@chromium.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mcgrof@kernel.org \
--cc=mpatocka@redhat.com \
--cc=mtk.manpages@gmail.com \
--cc=rdunlap@infradead.org \
--cc=viro@zeniv.linux.org.uk \
/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®