Re: [PATCH] futex: Avoid hash-bucket locking for mismatched waits
Thomas Gleixner <[email protected]>
| Newsgroups | org.kernel.vger.linux-kselftest,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <87zeyolmr5.ffs@fw13> |
On Mon, Aug 10 2026 at 13:35, Usama Arif wrote:
> On 08/08/2026 10:19, Thomas Gleixner wrote:
>> On Fri, Jul 31 2026 at 12:26, Usama Arif wrote:
>>>
>>> + /*
>>> + * A mismatch here refuses the wait without locating the hash bucket;
>>> + * a match is rechecked under the lock below before queueing.
>>> + *
>>> + * get_futex_key() runs get_user_pages_fast() only for shared futexes,
>>> + * so their page is resident and the non-faulting read suffices, with
>>> + * the locked path recovering if it does not. A private futex may
>>
>> That's a fairy tale:
>>
>> get_futex_key()
>> ...
>> // shared
>> get_user_pages_fast(); // gets a page reference
>> ...
>> folio = page_folio(page);
>> ...
>>
>> out:
>> folio_put(folio); // drops the page reference
>>
>> Thanks,
>>
>> tglx
>
> I will fix the comment if the discussion in the other thread hopefully
> works out and there is a v2. folio_put() does not immediately evict the
> page; however as you point out it removes the guarantee that it stays
> available.
>
> get_futex_key() has just resolved the shared page, so a non-faulting
> read is "very likely" to succeed. If it doesn't, we get -EFAULT and will
> then reach the existing locked check and continues to do what is done
> without the patch.
What's the point of that exercise?
If the user access fails and it can fail with a page fault because
it's preemptible context, then the operation is done and returns -EFAULT
to user space.
This special handling of private futexes does not buy any value at all,
actually it adds a pointless conditional and makes the code
incomprehensible no matter how much effort you put into a comment.
Thanks,
tglx