From: Oleg Nesterov <oleg@redhat.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Darren Hart <darren@dvhart.com>,
Thomas Gleixner <tglx@linutronix.de>,
Jerome Marchand <jmarchan@redhat.com>,
Larry Woodman <lwoodman@redhat.com>,
Mateusz Guzik <mguzik@redhat.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 0/1] futex: check PF_KTHREAD rather than !p->mm to filter out kthreads
Date: Thu, 5 Feb 2015 19:10:14 +0100 [thread overview]
Message-ID: <20150205181014.GA20244@redhat.com> (raw)
In-Reply-To: <20150205162725.GK5029@twins.programming.kicks-ass.net>
Let me first say that I simply do not know if PI+robust futex is actually
supposed (or guaranteed) to work.
Documentation/pi-futex.txt says
'robustness' and 'PI' are two orthogonal
properties of futexes, and all four combinations are possible: futex,
robust-futex, PI-futex, robust+PI-futex.
And exit_robust_list() checks bit 0 to detect the "PI" case, so I think
this should work.
However, this comment
/*
* This task is holding PI mutexes at exit time => bad.
* Kernel cleans up PI-state, but userspace is likely hosed.
* (Robust-futex cleanup is separate and might save the day for userspace.)
*/
above exit_pi_state_list() looks confusing. In fact it looks wrong if
PI+robust should work. Because handle_futex_death() seems to rely on
exit_pi_state_list.
Now, if it should work,
On 02/05, Peter Zijlstra wrote:
>
> So as long as we unhash _last_ I can't see this happening, we'll always
> find the task, the robust list walk doesn't care about PI state.
and it simply can't take care of PI state. ->pi_state can be NULL by
the time exit_robust_list() is called.
> But please, if you suspect, share a little more detail on how you see
> this happening, this is not code I've looked at in detail before.
Heh, I am reading it for the first time ;) So I can be easily wrong.
But afaics the race/problem is very simple. Suppose a task T locks a PI+robust
mutex and exits. I this case (I presume) sys_futex(uaddr, FUTEX_LOCK_PI)
from another task X must always succeed sooner or later. But
- X takes queue_lock() and reads *uaddr == T->pid. Need to setup
pi_state and wait. FUTEX_WAITERS is set.
- T exits and calls handle_futex_death(). This clears FUTEX_TID_MASK
and sets FUTEX_OWNER_DIED, without any lock.
T->pi_state_list is empty, exit_pi_state_list() does nothing.
T goes away or simply sets PF_EXITPIDONE (lets ignore PF_EXITING).
- X calls attach_to_pi_owner() and futex_find_get_task() returns NULL,
or we detect PF_EXITPIDONE, this doesn't really matter.
What does matter (unless I missed something) is that -ESRCH is wrong
in this case. This mutex was unlocked. It is robust, so we should not
miss this unlock.
So I think that in this case we either need to recheck that *uaddr is still the
same (and turn -ESRCH into -EAGAIN otherwise), or change handle_futex_death() to
serialize with X so that it can proceed and attach pi_state.
No?
Oleg.
next prev parent reply other threads:[~2015-02-05 18:11 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-02 14:05 [PATCH 0/1] futex: check PF_KTHREAD rather than !p->mm to filter out kthreads Oleg Nesterov
2015-02-02 14:05 ` [PATCH 1/1] " Oleg Nesterov
2015-02-04 10:48 ` Peter Zijlstra
2015-02-14 18:01 ` Davidlohr Bueso
2015-02-14 20:57 ` Oleg Nesterov
2015-02-14 21:15 ` Davidlohr Bueso
2015-02-14 21:54 ` Oleg Nesterov
2015-02-18 17:11 ` [tip:locking/core] locking/futex: Check " tip-bot for Oleg Nesterov
2015-02-02 15:11 ` [PATCH 0/1] futex: check " Peter Zijlstra
2015-02-02 15:13 ` Peter Zijlstra
2015-02-02 15:14 ` Peter Zijlstra
2015-02-02 16:20 ` Oleg Nesterov
2015-02-03 20:09 ` Oleg Nesterov
2015-02-04 11:12 ` Peter Zijlstra
2015-02-04 20:25 ` Oleg Nesterov
2015-02-05 16:27 ` Peter Zijlstra
2015-02-05 18:10 ` Oleg Nesterov [this message]
2015-02-06 10:46 ` Peter Zijlstra
2015-02-06 17:04 ` Oleg Nesterov
2015-02-09 20:38 ` Darren Hart
2015-02-10 11:14 ` Oleg Nesterov
2015-02-16 20:13 ` [PATCH 0/1] futex: don't spin waiting for PF_EXITING -> PF_EXITPIDONE transition Oleg Nesterov
2015-02-16 20:13 ` [PATCH 1/1] " Oleg Nesterov
2015-02-27 9:52 ` Peter Zijlstra
2015-02-27 11:54 ` Peter Zijlstra
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=20150205181014.GA20244@redhat.com \
--to=oleg@redhat.com \
--cc=darren@dvhart.com \
--cc=jmarchan@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lwoodman@redhat.com \
--cc=mguzik@redhat.com \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.