Re: [PATCH] inet: inet_defrag: Removing the usage of refcount_inc_not_zero

From: Eric Dumazet
Date: Mon Apr 15 2024 - 13:33:44 EST


On Mon, Apr 15, 2024 at 6:06 PM Abhinav Jain <jain.abhinav177@gmailcom> wrote:
>
> Remove refcount_inc_not_zero as per the listed TODO in the file.
> Used spin_(un)lock and refcount_* functions for synchronization.
>
> Signed-off-by: Abhinav Jain <jain.abhinav177@xxxxxxxxx>
> ---
> net/ipv4/inet_fragment.c | 9 +++++++--
> 1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/net/ipv4/inet_fragment.c b/net/ipv4/inet_fragment.c
> index c88c9034d630..e4838bbe0abb 100644
> --- a/net/ipv4/inet_fragment.c
> +++ b/net/ipv4/inet_fragment.c
> @@ -358,7 +358,6 @@ static struct inet_frag_queue *inet_frag_create(struct fqdir *fqdir,
> return q;
> }
>
> -/* TODO : call from rcu_read_lock() and no longer use refcount_inc_not_zero() */
> struct inet_frag_queue *inet_frag_find(struct fqdir *fqdir, void *key)
> {
> /* This pairs with WRITE_ONCE() in fqdir_pre_exit(). */
> @@ -375,8 +374,14 @@ struct inet_frag_queue *inet_frag_find(struct fqdir *fqdir, void *key)
> fq = inet_frag_create(fqdir, key, &prev);
> if (!IS_ERR_OR_NULL(prev)) {
> fq = prev;
> - if (!refcount_inc_not_zero(&fq->refcnt))
> + spin_lock(&fq->lock);
> + if (refcount_read(&fq->refcnt) > 0) {
> + refcount_inc(&fq->refcnt);
> + spin_unlock(&fq->lock);
> + } else {
> + spin_unlock(&fq->lock);
> fq = NULL;
> + }
>

This is bogus. I do not think you understood the comment.