Re: [PATCH v8 12/15] futex: Allow to re-allocate the private local hash.
From: Peter Zijlstra
Date: Tue Feb 04 2025 - 06:05:49 EST
On Mon, Feb 03, 2025 at 02:59:32PM +0100, Sebastian Andrzej Siewior wrote:
> @@ -159,11 +281,25 @@ struct futex_hash_bucket *futex_hash(union futex_key *key)
>
> bool futex_put_private_hash(struct futex_private_hash *hb_p)
> {
> - return false;
> + bool released;
> +
> + guard(preempt)();
> + released = rcuref_put_rcusafe(&hb_p->users);
> + if (released)
> + WRITE_ONCE(hb_p->released, true);
> + return released;
> }
>
> void futex_hash_put(struct futex_hash_bucket *hb)
> {
> + struct futex_private_hash *hb_p;
> +
> + if (hb->hb_slot == 0)
> + return;
> + hb_p = container_of(hb, struct futex_private_hash,
> + queues[hb->hb_slot - 1]);
> +
> + futex_put_private_hash(hb_p);
> }
>
> /**
> @@ -175,6 +311,14 @@ void futex_hash_put(struct futex_hash_bucket *hb)
> */
> void futex_hash_get(struct futex_hash_bucket *hb)
> {
> + struct futex_private_hash *hb_p;
> +
> + if (hb->hb_slot == 0)
> + return;
> + hb_p = container_of(hb, struct futex_private_hash,
> + queues[hb->hb_slot - 1]);
> +
> + WARN_ON_ONCE(!rcuref_get(&hb_p->users));
> }
> --- a/kernel/futex/futex.h
> +++ b/kernel/futex/futex.h
> @@ -115,6 +115,7 @@ static inline bool should_fail_futex(bool fshared)
> */
> struct futex_hash_bucket {
> atomic_t waiters;
> + unsigned int hb_slot;
> spinlock_t lock;
> struct plist_head chain;
> } ____cacheline_aligned_in_smp;
*groan*
Just sticking a pointer in was too complicated?
void futex_hash_put(struct futex_hash_bucket *hb)
{
struct futex_private_hash *ph = hb->private;
if (!ph)
return;
futex_put_private_hash(ph);
}