From: Matthew Wilcox <willy@infradead.org>
To: dri-devel@lists.freedesktop.org, linux-mm@kvack.org,
Souptick Joarder <jrdr.linux@gmail.com>,
linux-kernel@vger.kernel.org
Subject: Re: Signal handling in a page fault handler
Date: Wed, 4 Apr 2018 07:39:00 -0700 [thread overview]
Message-ID: <20180404143900.GA1777@bombadil.infradead.org> (raw)
In-Reply-To: <20180404093254.GC3881@phenom.ffwll.local>
On Wed, Apr 04, 2018 at 11:32:54AM +0200, Daniel Vetter wrote:
> So we've done some experiments for the case where the fault originated
> from kernel context (copy_to|from_user and friends). The fixup code seems
> to retry the copy once after the fault (in copy_user_handle_tail), if that
> fails again we get a short read/write. This might result in an -EFAULT,
> short read()/write() or anything else really, depending upon the syscall
> api.
>
> Except in some code paths in gpu drivers where we convert anything into
> -ERESTARTSYS/EINTR if there's a signal pending it won't ever result in the
> syscall getting restarted (well except maybe short read/writes if
> userspace bothers with that).
>
> So I guess gpu fault handlers indeed break the kernel's expectations, but
> then I think we're getting away with that because the inner workings of
> gpu memory objects is all heavily abstracted away by opengl/vulkan and
> friends.
>
> I guess what we could do is try to only do killable sleeps if it's a
> kernel fault, but that means wiring a flag through all the callchains. Not
> pretty. Except when there's a magic set of functions that would convert
> all interruptible sleeps to killable ones only for us.
I actually have plans to allow mutex_lock_{interruptible,killable} to
return -EWOULDBLOCK if a flag is set. So this doesn't seem entirely
unrelated. Something like this perhaps:
struct task_struct {
+ unsigned int sleep_state;
};
static noinline int __sched
-__mutex_lock_interruptible_slowpath(struct mutex *lock)
+__mutex_lock_slowpath(struct mutex *lock, long state)
{
- return __mutex_lock(lock, TASK_INTERRUPTIBLE, 0, NULL, _RET_IP_);
+ if (state == TASK_NOBLOCK)
+ return -EWOULDBLOCK;
+ return __mutex_lock(lock, state, 0, NULL, _RET_IP_);
}
+int __sched mutex_lock_state(struct mutex *lock, long state)
+{
+ might_sleep();
+
+ if (__mutex_trylock_fast(lock))
+ return 0;
+
+ return __mutex_lock_slowpath(lock, state);
+}
+EXPORT_SYMBOL(mutex_lock_state);
Then the page fault handler can do something like:
old_state = current->sleep_state;
current->sleep_state = TASK_INTERRUPTIBLE;
...
current->sleep_state = old_state;
This has the page-fault-in-a-signal-handler problem. I don't know if
there's a way to determine if we're already in a signal handler and use
a different sleep_state ...?
next prev parent reply other threads:[~2018-04-04 14:39 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-02 14:10 Signal handling in a page fault handler Matthew Wilcox
2018-04-03 12:33 ` Chris Wilson
2018-04-03 13:10 ` Matthew Wilcox
[not found] ` <152276164305.32747.4969221700358143640@mail.alporthouse.com>
2018-04-03 13:48 ` Matthew Wilcox
2018-04-03 13:12 ` Thomas Hellstrom
2018-04-03 14:48 ` Matthew Wilcox
2018-04-03 15:12 ` Daniel Vetter
2018-04-04 9:32 ` Daniel Vetter
2018-04-04 14:39 ` Matthew Wilcox [this message]
2018-04-04 15:15 ` Daniel Vetter
2018-04-04 16:24 ` Matthew Wilcox
2018-04-04 17:45 ` Daniel Vetter
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=20180404143900.GA1777@bombadil.infradead.org \
--to=willy@infradead.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=jrdr.linux@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.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;
as well as URLs for NNTP newsgroup(s).