From: Christoph Hellwig <hch@infradead.org>
To: Al Viro <viro@zeniv.linux.org.uk>
Cc: Christoph Hellwig <hch@infradead.org>,
Linus Torvalds <torvalds@linux-foundation.org>,
Jann Horn <jannh@google.com>,
linux-fsdevel <linux-fsdevel@vger.kernel.org>,
Linux List Kernel Mailing <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] fs: use KERNEL_DS instead of get_ds()
Date: Fri, 8 Mar 2019 08:20:17 -0800 [thread overview]
Message-ID: <20190308162017.GA26207@infradead.org> (raw)
In-Reply-To: <20190308142331.GE2217@ZenIV.linux.org.uk>
On Fri, Mar 08, 2019 at 02:23:31PM +0000, Al Viro wrote:
> You do realize that nested pairs of that sort are not all there is?
> Even leaving m68k aside (there the same registers that select
> userland or kernel for that kind of access can be used e.g. for
> writeback control, or to switch to accessing sun3 MMU tables, etc.)
Yes. And the whole point is to keep these uses clear and separate.
> there are
> * temporary switches to USER_DS in things like unaligned
> access handlers, etc., where the kernel is doing emulation of possibly
> userland insns; similar for oops code dumping, etc.
> * use_mm()/unuse_mm() should probably switch to USER_DS and
> back, rather than doing that in callers.
> * switch to USER_DS (and no, it's *not* "USER_DS unless we started
> with KERNEL_DS" - nested counter is no-go here) for perf callbacks.
> * regular non-paired switches to USER_DS: do_exit() and
> flush_old_exec().
And that is probably the close to full list of callers that want
to explicitly enable access to the user address space, and thus
mark the thread as a user thread (and occasionally clear that in e.g.
unuse_mm).
Unless I'm completely missing something our general rule of thumb
should be:
- threads are started with uaccess kernel turned on (count = 1)
- if we execute in userspace we switch to user uaccess (count = 0)
- same for use_mm style threads that want user access
- every current random kernel code override increments the refcount
and drops the reference when done
- force uaccess cases like do_exit or the validation check on
return to userspace force it back to 0.
Initially each 1 > 0 transition (decrement or force) will do
set_fs(USER_DS), each 0 > 1 transition will do set_fs(KERNEL_DS).
Then later architectures can kill the set_fs API, and potentially
optimize things by getting rid of the addr_limit field in its current
form.
prev parent reply other threads:[~2019-03-08 16:20 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-01 20:08 [PATCH] fs: use KERNEL_DS instead of get_ds() Jann Horn
2019-03-02 3:40 ` Al Viro
2019-03-05 0:23 ` Linus Torvalds
2019-03-08 14:01 ` Christoph Hellwig
2019-03-08 14:23 ` Al Viro
2019-03-08 16:20 ` Christoph Hellwig [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=20190308162017.GA26207@infradead.org \
--to=hch@infradead.org \
--cc=jannh@google.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@linux-foundation.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;
as well as URLs for NNTP newsgroup(s).