2006-03-13 15:43:32

by Roland Dreier

[permalink] [raw]
Subject: Re: [PATCH 5/6 v2] IB: IP address based RDMA connection manager

It seems that cma_detach_from_dev():

> +static void cma_detach_from_dev(struct rdma_id_private *id_priv)
> +{
> + list_del(&id_priv->list);
> + if (atomic_dec_and_test(&id_priv->cma_dev->refcount))
> + wake_up(&id_priv->cma_dev->wait);
> + id_priv->cma_dev = NULL;
> +}

doesn't need to do atomic_dec_and_test(), because it is never dropping
the last reference to id_priv (and in fact if it was, the last line
would be a use-after-free bug).

Does it make sense to replace it with:

static void cma_detach_from_dev(struct rdma_id_private *id_priv)
{
list_del(&id_priv->list);
/*
* cma_detach_from_dev() will never be dropping the last
* reference to id_priv, so no need to test here.
*/
atomic_dec(&id_priv->cma_dev->refcount);
id_priv->cma_dev = NULL;
}

on my x86_64 build that's worth

add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-40 (-40)
function old new delta
cma_detach_from_dev 106 66 -40

- R.


2006-03-13 17:11:39

by Hefty, Sean

[permalink] [raw]
Subject: RE: [PATCH 5/6 v2] IB: IP address based RDMA connection manager

> > +static void cma_detach_from_dev(struct rdma_id_private *id_priv)
> > +{
> > + list_del(&id_priv->list);
> > + if (atomic_dec_and_test(&id_priv->cma_dev->refcount))
> > + wake_up(&id_priv->cma_dev->wait);
> > + id_priv->cma_dev = NULL;
> > +}
>
>doesn't need to do atomic_dec_and_test(), because it is never dropping
>the last reference to id_priv (and in fact if it was, the last line
>would be a use-after-free bug).

It's dropping the reference on cma_dev, as opposed to id_priv.

- Sean

2006-03-13 17:26:47

by Roland Dreier

[permalink] [raw]
Subject: Re: [PATCH 5/6 v2] IB: IP address based RDMA connection manager

Sean> It's dropping the reference on cma_dev, as opposed to
Sean> id_priv.

Duh, sorry.

- R.