From: Waiman Long <waiman.long@hpe.com>
To: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
Jonathan Corbet <corbet@lwn.net>, <linux-kernel@vger.kernel.org>,
<linux-doc@vger.kernel.org>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Davidlohr Bueso <dave@stgolabs.net>,
Mike Galbraith <umgwanakikbuti@gmail.com>,
Jason Low <jason.low2@hpe.com>,
Scott J Norton <scott.norton@hpe.com>,
Douglas Hatch <doug.hatch@hpe.com>
Subject: Re: [PATCH v3 07/13] futex: Throughput-optimized (TP) futexes
Date: Sat, 1 Oct 2016 21:12:09 -0400 [thread overview]
Message-ID: <57F05EE9.20702@hpe.com> (raw)
In-Reply-To: <alpine.DEB.2.20.1610010844490.5067@nanos>
On 10/01/2016 02:47 AM, Thomas Gleixner wrote:
> On Fri, 30 Sep 2016, Waiman Long wrote:
>> + WRITE_ONCE(state->owner, current);
>> + preempt_disable();
>> + for (;;) {
>> + ret = futex_trylock(uaddr, vpid,&uval, true);
> Did you actually read what I said? You CANNOT access userspace in a preempt
> disabled region without disabling pagefaults and handle the resulting
> wreckage yourself.
I think I had missed that comment. My bad:-(
I will fix that with the code changes below. I will also double-check
your comments again to see if I miss some others.
Cheers,
Longman
---------------------------[ cut here
]-----------------------------------------
diff --git a/kernel/futex.c b/kernel/futex.c
index bc16eca..132a36d 100644
--- a/kernel/futex.c
+++ b/kernel/futex.c
@@ -3520,6 +3520,13 @@ static int futex_spin_on_owner(u32 __user *uaddr,
u32 vpid,
bool on_owner_pi_list = false;
WRITE_ONCE(state->owner, current);
+retry:
+ /*
+ * The preempt_disable() has similar effect as pagefault_disable().
+ * As a result, we will have to disable page fault as well and
handle
+ * the case of faulting in the futex word.
+ */
+ pagefault_disable();
preempt_disable();
for (;; loop--) {
ret = futex_trylock(uaddr, vpid, &uval, true);
@@ -3648,6 +3655,14 @@ static int futex_spin_on_owner(u32 __user *uaddr,
u32 vpid,
}
out:
preempt_enable();
+ pagefault_enable();
+
+ if (ret == -EFAULT) {
+ ret = fault_in_user_writeable(uaddr);
+ if (!ret)
+ goto retry;
+ }
+
if (owner_task) {
if (on_owner_pi_list)
task_pi_list_del(owner_task, state, false);
next prev parent reply other threads:[~2016-10-02 1:12 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-30 21:26 [PATCH v3 00/13] futex: Introducing throughput-optimized futexes Waiman Long
2016-09-30 21:26 ` [PATCH v3 01/13] futex: Consolidate duplicated timer setup code Waiman Long
2016-09-30 21:26 ` [PATCH v3 02/13] futex: Rename futex_pi_state to futex_state Waiman Long
2016-09-30 21:26 ` [PATCH v3 03/13] futex: Add helpers to get & cmpxchg futex value without lock Waiman Long
2016-09-30 21:26 ` [PATCH v3 04/13] futex: Consolidate pure pi_state_list add & delete codes to helpers Waiman Long
2016-09-30 21:26 ` [PATCH v3 05/13] futex: Add a new futex type field into futex_state Waiman Long
2016-09-30 21:26 ` [PATCH v3 06/13] futex: Allow direct attachment of futex_state objects to hash bucket Waiman Long
2016-09-30 21:26 ` [PATCH v3 07/13] futex: Throughput-optimized (TP) futexes Waiman Long
2016-10-01 6:47 ` Thomas Gleixner
2016-10-02 1:12 ` Waiman Long [this message]
2016-09-30 21:26 ` [PATCH v3 08/13] futex: Enable robust handling of TP futexes Waiman Long
2016-09-30 21:26 ` [PATCH v3 09/13] futex: Implement lock handoff for TP futexes to prevent lock starvation Waiman Long
2016-09-30 21:26 ` [PATCH v3 10/13] futex: Inform FUTEX_LOCK callers on how the lock is acquired Waiman Long
2016-09-30 21:26 ` [PATCH v3 11/13] futex: Add timeout support to TP futexes Waiman Long
2016-09-30 21:26 ` [PATCH v3 12/13] futex, doc: TP futexes document Waiman Long
2016-09-30 21:26 ` [PATCH v3 13/13] perf bench: New microbenchmark for userspace mutex performance Waiman Long
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=57F05EE9.20702@hpe.com \
--to=waiman.long@hpe.com \
--cc=acme@kernel.org \
--cc=corbet@lwn.net \
--cc=dave@stgolabs.net \
--cc=doug.hatch@hpe.com \
--cc=jason.low2@hpe.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=scott.norton@hpe.com \
--cc=tglx@linutronix.de \
--cc=umgwanakikbuti@gmail.com \
/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
Powered by JetHome