From: Beau Belgrave <beaub@linux.microsoft.com>
To: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: rostedt@goodmis.org, mhiramat@kernel.org,
dcook@linux.microsoft.com, alanau@linux.microsoft.com,
linux-trace-devel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [RFC PATCH 2/2] tracing/user_events: Fixup enable faults asyncly
Date: Fri, 28 Oct 2022 15:42:56 -0700 [thread overview]
Message-ID: <20221028224256.GA202@W11-BEAU-MD.localdomain> (raw)
In-Reply-To: <a18e940d-8423-0294-23b4-f2702313f3eb@efficios.com>
On Fri, Oct 28, 2022 at 06:19:10PM -0400, Mathieu Desnoyers wrote:
> On 2022-10-27 18:40, Beau Belgrave wrote:
> > When events are enabled within the various tracing facilities, such as
> > ftrace/perf, the event_mutex is held. As events are enabled pages are
> > accessed. We do not want page faults to occur under this lock. Instead
> > queue the fault to a workqueue to be handled in a process context safe
> > way without the lock.
> >
> > The enable address is disabled while the async fault-in occurs. This
> > ensures that we don't attempt fault-in more than is necessary. Once the
> > page has been faulted in, the address write is attempted again. If the
> > page couldn't fault-in, then we wait until the next time the event is
> > enabled to prevent any potential infinite loops.
>
> I'm also unclear about how the system call initiating the enabled state
> change is delayed (or not) when a page fault is queued.
>
It's not, if needed we could call schedule_delayed_work(). However, I
don't think we need it. When pin_user_pages_remote is invoked, it's with
FOLL_NOFAULT. This will tell us if we need to fault pages in, we then
call fixup_user_fault with unlocked value passed. This will cause the
fixup to retry and get the page in.
It's called out in the comments for this exact purpose (lucked out
here):
mm/gup.c
* This is meant to be called in the specific scenario where for locking reasons
* we try to access user memory in atomic context (within a pagefault_disable()
* section), this returns -EFAULT, and we want to resolve the user fault before
* trying again.
The fault in happens in a workqueue, this is the same way KVM does it's
async page fault logic, so it's not a new pattern. As soon as the
fault-in is done, we have a page we should be able to use, so we
re-attempt the write immediately. If the write fails, another queue
happens and we could loop, but not like the unmap() case I replied with
earlier.
> I would expect that when a page fault is needed, after enqueuing work to the
> worker thread, the system call initiating the state change would somehow
> wait for a completion (after releasing the user events mutex). That
> completion would be signaled by the worker thread either if the page fault
> fails, or if the state change is done.
>
I didn't see a generic fault-in + notify anywhere, do you know of one I
could use? Otherwise, it seems the pattern used is check fault, fault-in
via workqueue, re-attempt.
> Thoughts ?
>
> Thanks,
>
> Mathieu
>
Thanks,
-Beau
next prev parent reply other threads:[~2022-10-28 22:43 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-27 22:40 [RFC PATCH 0/2] tracing/user_events: Remote write ABI Beau Belgrave
2022-10-27 22:40 ` [RFC PATCH 1/2] tracing/user_events: Use remote writes for event enablement Beau Belgrave
2022-10-29 14:44 ` Mathieu Desnoyers
2022-10-31 16:38 ` Beau Belgrave
2022-10-31 14:47 ` Masami Hiramatsu
2022-10-31 16:46 ` Beau Belgrave
2022-10-31 23:55 ` Masami Hiramatsu
2022-11-01 16:45 ` Beau Belgrave
2022-10-27 22:40 ` [RFC PATCH 2/2] tracing/user_events: Fixup enable faults asyncly Beau Belgrave
2022-10-28 22:07 ` Mathieu Desnoyers
2022-10-28 22:35 ` Beau Belgrave
2022-10-29 14:23 ` Mathieu Desnoyers
2022-10-31 16:58 ` Beau Belgrave
2022-10-28 22:19 ` Mathieu Desnoyers
2022-10-28 22:42 ` Beau Belgrave [this message]
2022-10-29 14:40 ` Mathieu Desnoyers
2022-10-30 11:45 ` Mathieu Desnoyers
2022-10-31 17:18 ` Beau Belgrave
2022-10-31 17:12 ` Beau Belgrave
2022-10-28 21:50 ` [RFC PATCH 0/2] tracing/user_events: Remote write ABI Mathieu Desnoyers
2022-10-28 22:17 ` Beau Belgrave
2022-10-29 13:58 ` Mathieu Desnoyers
2022-10-31 16:53 ` Beau Belgrave
2022-11-02 13:46 ` Mathieu Desnoyers
2022-11-02 17:18 ` Beau Belgrave
2022-10-31 14:15 ` Masami Hiramatsu
2022-10-31 15:27 ` Mathieu Desnoyers
2022-10-31 17:27 ` Beau Belgrave
2022-10-31 18:25 ` Mathieu Desnoyers
2022-11-01 13:52 ` Masami Hiramatsu
2022-11-01 16:55 ` Beau Belgrave
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=20221028224256.GA202@W11-BEAU-MD.localdomain \
--to=beaub@linux.microsoft.com \
--cc=alanau@linux.microsoft.com \
--cc=dcook@linux.microsoft.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-devel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=mhiramat@kernel.org \
--cc=rostedt@goodmis.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).