All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bart Van Assche <bvanassche-HInyCGIudOg@public.gmane.org>
To: dongsu.park-EIkl63zCoXaH+58JC4qpiA@public.gmane.org
Cc: dillowda-1Heg1YXhbW8@public.gmane.org,
	roland-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org,
	sean.hefty-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org,
	hal.rosenstock-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org,
	JBottomley-bzQdu9zFT3WakBO8gow8eQ@public.gmane.org,
	linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH 1/5] ib_srp: free memory correctly in srp_free_iu()
Date: Sat, 01 Sep 2012 07:32:37 +0000	[thread overview]
Message-ID: <5041BA15.1090905@acm.org> (raw)
In-Reply-To: <1346443241-24844-2-git-send-email-dongsu.park-EIkl63zCoXaH+58JC4qpiA@public.gmane.org>

On 08/31/12 20:00, dongsu.park-EIkl63zCoXaH+58JC4qpiA@public.gmane.org wrote:
> From: Dongsu Park <dongsu.park-EIkl63zCoXaH+58JC4qpiA@public.gmane.org>
> 
> As a potential fix for a race condition in srp_free_iu(),
> hold a mutex in srp_free_target_ib() before calling srp_free_iu().
> 
> In addition, also clear rx/tx ring after freeing memory.
> Both rx_ring[] and tx_ring[] should be reinitialized to NULL,
> to prevent other tasks from accessing the freed memory.
> 
> Signed-off-by: Dongsu Park <dongsu.park-EIkl63zCoXaH+58JC4qpiA@public.gmane.org>
> ---
>  drivers/infiniband/ulp/srp/ib_srp.c | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/infiniband/ulp/srp/ib_srp.c b/drivers/infiniband/ulp/srp/ib_srp.c
> index 7ae5a00..a0d0ca2 100644
> --- a/drivers/infiniband/ulp/srp/ib_srp.c
> +++ b/drivers/infiniband/ulp/srp/ib_srp.c
> @@ -291,10 +291,16 @@ static void srp_free_target_ib(struct srp_target_port *target)
>  	ib_destroy_cq(target->send_cq);
>  	ib_destroy_cq(target->recv_cq);
>  
> -	for (i = 0; i < SRP_RQ_SIZE; ++i)
> +	mutex_lock(&target->mutex);
> +	for (i = 0; i < SRP_RQ_SIZE; ++i) {
>  		srp_free_iu(target->srp_host, target->rx_ring[i]);
> -	for (i = 0; i < SRP_SQ_SIZE; ++i)
> +		target->rx_ring[i] = NULL;
> +	}
> +	for (i = 0; i < SRP_SQ_SIZE; ++i) {
>  		srp_free_iu(target->srp_host, target->tx_ring[i]);
> +		target->tx_ring[i] = NULL;
> +	}
> +	mutex_unlock(&target->mutex);
>  }
>  
>  static void srp_path_rec_completion(int status,

It would be interesting if you could provide a little more background
information about this patch. srp_remove_target() waits until all users
of rx_ring[] and tx_ring[] have finished before invoking
srp_free_target_ib(). Or at least, that's how it should work. Did you
come up with this patch after source reading or does this patch address
an issue you hit during testing ? In the last case we have to dig deeper
and we have to find out why it's possible that rx_ring[] and/or
tx_ring[] were accessed while srp_free_target_ib() was in progress.

Bart.
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  parent reply	other threads:[~2012-09-01  7:32 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-31 20:00 [PATCH 0/5] Fix bugs in ib_srp patches for H.A. purposes dongsu.park-EIkl63zCoXaH+58JC4qpiA
2012-08-31 20:00 ` dongsu.park
2012-08-31 20:00 ` [PATCH 1/5] ib_srp: free memory correctly in srp_free_iu() dongsu.park
     [not found]   ` <1346443241-24844-2-git-send-email-dongsu.park-EIkl63zCoXaH+58JC4qpiA@public.gmane.org>
2012-09-01  7:32     ` Bart Van Assche [this message]
2012-08-31 20:00 ` [PATCH 2/5] ib_srp: removed superfluous warning in send timeout case dongsu.park
     [not found]   ` <1346443241-24844-3-git-send-email-dongsu.park-EIkl63zCoXaH+58JC4qpiA@public.gmane.org>
2012-09-01  7:44     ` Bart Van Assche
2012-08-31 20:00 ` [PATCH 3/5] ib_srp: hold a mutex when adding a new target port dongsu.park
     [not found]   ` <1346443241-24844-4-git-send-email-dongsu.park-EIkl63zCoXaH+58JC4qpiA@public.gmane.org>
2012-09-01  7:55     ` Bart Van Assche
2012-08-31 20:00 ` [PATCH 4/5] ib_srp: check if rport->lld_data is NULL before removing rport dongsu.park
     [not found]   ` <1346443241-24844-5-git-send-email-dongsu.park-EIkl63zCoXaH+58JC4qpiA@public.gmane.org>
2012-09-01  7:59     ` Bart Van Assche
     [not found] ` <1346443241-24844-1-git-send-email-dongsu.park-EIkl63zCoXaH+58JC4qpiA@public.gmane.org>
2012-08-31 20:00   ` [PATCH 5/5] ib_srp: fix an error accessing invalid memory in rport_dev_loss_timedout dongsu.park-EIkl63zCoXaH+58JC4qpiA
2012-08-31 20:00     ` dongsu.park
2012-09-01  8:09   ` [PATCH 0/5] Fix bugs in ib_srp patches for H.A. purposes Bart Van Assche
2012-09-01  8:09     ` Bart Van Assche

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5041BA15.1090905@acm.org \
    --to=bvanassche-hinycgiudog@public.gmane.org \
    --cc=JBottomley-bzQdu9zFT3WakBO8gow8eQ@public.gmane.org \
    --cc=dillowda-1Heg1YXhbW8@public.gmane.org \
    --cc=dongsu.park-EIkl63zCoXaH+58JC4qpiA@public.gmane.org \
    --cc=hal.rosenstock-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=roland-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    --cc=sean.hefty-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.