From: Minchan Kim <minchan.kim@gmail.com>
To: Eric Dumazet <dada1@cosmosbay.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
lkml <linux-kernel@vger.kernel.org>
Subject: Re: Question about PRIVATE_FUTEX
Date: Fri, 27 Mar 2009 15:20:35 +0900 [thread overview]
Message-ID: <28c262360903262320rd102645i9bef602ec16dbf63@mail.gmail.com> (raw)
In-Reply-To: <49CC693D.8050901@cosmosbay.com>
On Fri, Mar 27, 2009 at 2:50 PM, Eric Dumazet <dada1@cosmosbay.com> wrote:
> Minchan Kim a écrit :
>> Thanks for kind explanation.
>>
>> On Fri, Mar 27, 2009 at 1:56 PM, Eric Dumazet <dada1@cosmosbay.com> wrote:
>>> Minchan Kim a écrit :
>>>> Hi, Peter and Eric.
>>>>
>>>> I am not expert about futex.
>>>> I am sorry if this is dumb question.
>>>>
>>>> If we use private futex, get_futex_key don't call get_user_pages_fast
>>>> which pins page at page table.
>>>> Then, get_futex_value_locked calls __cpy_from_user_inatomic with
>>>> pagefault_disable.
>>>>
>>>> Who make sure the user page is mapped at app's page table ?
>>>>
>>> Nothing makes sure user page is mapped, as we dont have to (for private futexes
>>> at least, since the 'key' is a combination of the futex virtual address (not
>>> depending on the underlying physical page) and the task mm (sort of a static
>>> offset per task)
>>> If no page is mapped, a normal error should be returned to user, since
>>> access to futex location will trigger a fault.
>>>
>>
>> I mean as follows.
>> It seems even shared futex case.
>>
>> After calling get_user_pages_fast, get_futex_key calls unlock_page and
>> put_page, too. Then futex_wait calls get_futex_value_locked.
>>
>> Generally, current page->count is one and nolocked.
>> I think kernel reclaimer can reclaim the page.
>>
>> Wouldn't kernel reclaim the page between get_fuex_key and
>> get_futex_value_locked ?
>> If kernel reclaimed the page, __copy_from_user_inatomic can happens
>> page fault although pagefault_disable is on.
>>
>> How do we make sure this race condition ?
>> Do I miss something ?
>>
>
> Hmmm, so your question is not about PRIVATE futexes, but shared ones.
>
> I guess if page is no more present, its not a problem since
> get_futex_value_locked() returns an error. We then take a slow
> path, calling get_user() and retrying whole futex logic.
Indeed.
I misunderstood about __copy_from_user_inatomic.
It never sleep.
> However, comment at line 1213 is misleading I guess, since
> we dont hold mmap semaphore anymore ?
>
> * for shared futexes, we hold the mmap semaphore, so the mapping
> * cannot have changed since we looked it up in get_futex_key.
> */
> ret = get_futex_value_locked(&uval, uaddr);
>
> So if page was un-mapped by another thread, and re-mapped to another physical
> page, then this thread might sleep on 'kernel futex' not anymore reachable...
>
> User error, as it is not supposed to happen in a sane program, undefined
> result...
Yes. How about removing confusing comments ?
Thanks for great explanation :)
--
Kinds regards,
Minchan Kim
next prev parent reply other threads:[~2009-03-27 6:20 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-27 2:12 Minchan Kim
2009-03-27 4:32 ` Minchan Kim
2009-03-27 4:56 ` Eric Dumazet
2009-03-27 5:20 ` Minchan Kim
2009-03-27 5:50 ` Eric Dumazet
2009-03-27 6:20 ` Minchan Kim [this message]
2009-03-27 8:49 ` Peter Zijlstra
2009-03-27 10:56 ` Minchan Kim
2009-03-27 11:14 ` Peter Zijlstra
2009-03-27 11:37 ` Minchan Kim
2009-03-27 15:43 ` Darren Hart
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=28c262360903262320rd102645i9bef602ec16dbf63@mail.gmail.com \
--to=minchan.kim@gmail.com \
--cc=dada1@cosmosbay.com \
--cc=linux-kernel@vger.kernel.org \
--cc=peterz@infradead.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
all inboxes | Powered by JetHome®