Re: [PATCH] rhashtable: Fix potential deadlock by moving schedule_work outside lock
From: Herbert Xu
Date: Thu Dec 12 2024 - 07:34:17 EST
On Thu, Nov 28, 2024 at 04:16:25AM -0800, Breno Leitao wrote:
>
> diff --git a/lib/rhashtable.c b/lib/rhashtable.c
> index 6c902639728b767cc3ee42c61256d2e9618e6ce7..5a27ccd72db9a25d92d1ed2f8d519afcfc672afe 100644
> --- a/lib/rhashtable.c
> +++ b/lib/rhashtable.c
> @@ -585,9 +585,6 @@ static struct bucket_table *rhashtable_insert_one(
> rht_assign_locked(bkt, obj);
>
> atomic_inc(&ht->nelems);
> - if (rht_grow_above_75(ht, tbl))
> - schedule_work(&ht->run_work);
> -
> return NULL;
> }
>
> @@ -624,6 +621,9 @@ static void *rhashtable_try_insert(struct rhashtable *ht, const void *key,
> data = ERR_CAST(new_tbl);
>
> rht_unlock(tbl, bkt, flags);
> + if (rht_grow_above_75(ht, tbl))
> + schedule_work(&ht->run_work);
> +
The growth check should stay with the atomic_inc. Something like
this should work:
if (PTR_ERR(data) == -ENOENT && !new_tbl) {
atomic_inc(&ht->nelems);
if (rht_grow_above_75(ht, tbl))
schedule_work(&ht->run_work);
break;
}
Could you please resend this via linux-crypto?
Thanks,
--
Email: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt